4

I have 1 process that writes to a specific section of shared memory (i.e. "/falcon" )in a docker container.

Docker image: dockersharedmemory/shmclient

I have another process that initially creates and reads the same section of shared memory(i.e. "/falcon" ) every second in another docker container.

Docker image: dockersharedmemory/shmserver

When I run the two containers using the following commands I am able to read and write in each container respectfully:

docker run -d -v /dev:/dev dockersharedmemory/shmserver

docker run -d -v /dev:/dev dockersharedmemory/shmclient

When I use the "--ipc" option per documentation i can't get it to work:

docker run -d --ipc=host dockersharedmemory/shmserver

docker run -d --ipc=host dockersharedmemory/shmclient

neither

docker run -d dockersharedmemory/shmserver

drunk_feynman

docker run -d --ipc=container:drunk_feynman dockersharedmemory/shmclient

happy_fermi

Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8/1.4.1
OS/Arch (client): linux/amd64
Server version: 1.4.1
Server API version: 1.16
Go version (server): go1.3.3
Git commit (server): 5bc2ff8/1.4.1

I have a working example now with a combination of the commands on the host by punching huge holes in the container with a combination of volumes and ipc: docker run -d -v /dev/shm:/dev/shm --ipc=host dockersharedmemory/shmserver docker run -d -v /dev/shm:/dev/shm --ipc=host dockersharedmemory/shmclient

Michael
  • 546
  • 1
  • 7
  • 19
  • You do understand that Docker is supposed to isolate processes from each other? Not clear to me what you're trying to achieve. – Mark O'Connor Mar 20 '15 at 20:30
  • 1
    I want to share ipc amongst certain containers that rely on shared memory. The documentation http://docs.docker.com/reference/run/#ipc-settings states that it is possible, i am just not able to get it to work using the docker run --ipc option. – Michael Mar 20 '15 at 21:24

1 Answers1

2

You still need -v /dev:/dev what happens if you do

docker run -d -v /dev:/dev --ipc=host dockersharedmemory/shmserver

docker run -d -v /dev:/dev --ipc=host dockersharedmemory/shmclient

If you dont mount bind /dev/ then the container cannot see whats inside /dev/ which is where your IPC/shm resides isnt it ?

resultsway
  • 12,299
  • 7
  • 36
  • 43
  • The "-v" options mounts the "host" shared memory. This is a valuable part of the story. The other part of the story is allocating shared memory on a single container and then accessing the shared memory from a second container. The documentaton http://docs.docker.com/reference/run/#ipc-settings seems to state that you can accomplish this shared memory between containers using the --ipc=container: option. – Michael Mar 23 '15 at 15:52
  • so your last option should work. it should do a setns of first container in the second. you can try strace or do a docker inspect, the docker log should give you some clue. Make sure you look at the /proc/pid/ of the second process. – resultsway Mar 23 '15 at 17:47
  • `docker run -d dockerclientserver/shmserver` `sick_goodall` `docker run -it --ipc container:sick_goodall` `trusting_rosalind` i can read the shared memory segment allocated by the process in "sick_goodall" if i run the second process in "sick_goodall." The second process in "trusting_rosalind" fails to read or write to the shared memory in "sick_goodall." `docker inspect trusting_rosalind` `...` ` "IpcMode": "container:sick_goodall",` `...` – Michael Mar 23 '15 at 19:07
  • i am able to create the same shared memory segment name (i.e. "/falcon") in the second container with the `"--ipc container:sick_goodall"` option. The shared memory does not seem to map with the --ipc option or i am missing something. – Michael Mar 23 '15 at 19:16
  • If you do docker run -ti ... /bin/bash (instead of shmclient) you will be able to see if your folder is properly mounted or not. – resultsway Mar 23 '15 at 19:26
  • my folders are not mounted when i use just the `--ipc`. Are you proposing that i can mount the drives from one container to another using `-v`? I thought `-v` was only from the host to container not container to container? – Michael Mar 23 '15 at 19:40
  • when i try mounting /dev/shm with `-v /dev/shm` my program writes the shared memory directly under `/dev/` instead of under `/dev/shm` – Michael Mar 24 '15 at 00:17