I'm setting up two docker containers - one as a server to hold data in memory, and the other as a client to access that data. In order to do so, I believe I need to use the --ipc
flag to share memory between the containers. The Docker documentation explains the --ipc
flag pretty well. What makes sense to me according to the documentation is running:
docker run -d --ipc=shareable data-server
docker run -d --ipc=container:data-server data-client
But all of the Stackoverflow questions I've read (1, 2, 3, 4) link both containers directly to the host:
docker run -d --ipc=host data-server
docker run -d --ipc=host data-client
Which is more appropriate for this use case? If ipc=host
is better, when would you use ipc=shareable
?
From doc:
--ipc="MODE" : Set the IPC mode for the container
"shareable": Own private IPC namespace, with a possibility to share it with other containers.
"host": Use the host system’s IPC namespace.
The difference between shareable
and host
is whether the host can access the shared memory.
Considering the security of the service, using host
exposes the IPC namespace to attackers who have control of the host machine. With shareable
, the IPC namespace is only accessible inside of the containers, which may contain any attacks. The host
mode exists to allow cooperation between a container and its host.
It's often difficult to know all the details of the environment and requirements of the asker, so host
tends to be the most commonly recommended because it is easiest to understand and configure.