You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow IPC namespace to be shared between containers or with the host
Some workloads rely on IPC for communications with other processes. We
would like to split workloads between two container but still allow them
to communicate though shared IPC.
This patch mimics the --net code to allow --ipc=host to not split off
the IPC Namespace. ipc=container:CONTAINERID to share ipc between containers
If you share IPC between containers, then you need to make sure SELinux labels
match.
Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
Copy file name to clipboardExpand all lines: docs/man/docker-run.1.md
+77-4Lines changed: 77 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ docker-run - Run a command in a new container
23
23
[**--expose**[=*[]*]]
24
24
[**-h**|**--hostname**[=*HOSTNAME*]]
25
25
[**-i**|**--interactive**[=*false*]]
26
+
[**--ipc**[=*[]*]]
26
27
[**--security-opt**[=*[]*]]
27
28
[**--link**[=*[]*]]
28
29
[**--lxc-conf**[=*[]*]]
@@ -142,6 +143,12 @@ ENTRYPOINT.
142
143
**-i**, **--interactive**=*true*|*false*
143
144
When set to true, keep stdin open even if not attached. The default is false.
144
145
146
+
**--ipc**=[]
147
+
Set the IPC mode for the container
148
+
**container**:<*name*|*id*>: reuses another container's IPC stack
149
+
**host**: use the host's IPC stack inside the container.
150
+
Note: the host mode gives the container full access to local IPC and is therefore considered insecure.
151
+
145
152
**--security-opt**=*secdriver*:*name*:*value*
146
153
"label:user:USER" : Set the label user for the container
147
154
"label:role:ROLE" : Set the label role for the container
@@ -183,10 +190,11 @@ and foreground Docker containers.
183
190
184
191
**--net**="bridge"
185
192
Set the Network mode for the container
186
-
'bridge': creates a new network stack for the container on the docker bridge
187
-
'none': no networking for this container
188
-
'container:<name|id>': reuses another container network stack
189
-
'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.
193
+
**bridge**: creates a new network stack for the container on the docker bridge
194
+
**none**: no networking for this container
195
+
**container**:<*name*|*id*>: reuses another container's network stack
196
+
**host**: use the host network stack inside the container.
197
+
Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.
190
198
191
199
**--mac-address**=*macaddress*
192
200
Set the MAC address for the container's Ethernet device:
@@ -310,6 +318,71 @@ you’d like to connect instead, as in:
310
318
311
319
# docker run -a stdin -a stdout -i -t fedora /bin/bash
312
320
321
+
## Sharing IPC between containers
322
+
323
+
Using shm_server.c available here: http://www.cs.cf.ac.uk/Dave/C/node27.html
324
+
325
+
Testing `--ipc=host` mode:
326
+
327
+
Host shows a shared memory segment with 7 pids attached, happens to be from httpd:
328
+
329
+
```
330
+
$ sudo ipcs -m
331
+
332
+
------ Shared Memory Segments --------
333
+
key shmid owner perms bytes nattch status
334
+
0x01128e25 0 root 600 1000 7
335
+
```
336
+
337
+
Now run a regular container, and it correctly does NOT see the shared memory segment from the host:
338
+
339
+
```
340
+
$ sudo docker run -it shm ipcs -m
341
+
342
+
------ Shared Memory Segments --------
343
+
key shmid owner perms bytes nattch status
344
+
```
345
+
346
+
Run a container with the new `--ipc=host` option, and it now sees the shared memory segment from the host httpd:
347
+
348
+
```
349
+
$ sudo docker run -it --ipc=host shm ipcs -m
350
+
351
+
------ Shared Memory Segments --------
352
+
key shmid owner perms bytes nattch status
353
+
0x01128e25 0 root 600 1000 7
354
+
```
355
+
Testing `--ipc=container:CONTAINERID` mode:
356
+
357
+
Start a container with a program to create a shared memory segment:
358
+
```
359
+
sudo docker run -it shm bash
360
+
$ sudo shm/shm_server &
361
+
$ sudo ipcs -m
362
+
363
+
------ Shared Memory Segments --------
364
+
key shmid owner perms bytes nattch status
365
+
0x0000162e 0 root 666 27 1
366
+
```
367
+
Create a 2nd container correctly shows no shared memory segment from 1st container:
368
+
```
369
+
$ sudo docker run shm ipcs -m
370
+
371
+
------ Shared Memory Segments --------
372
+
key shmid owner perms bytes nattch status
373
+
```
374
+
375
+
Create a 3rd container using the new --ipc=container:CONTAINERID option, now it shows the shared memory segment from the first:
376
+
377
+
```
378
+
$ sudo docker run -it --ipc=container:ed735b2264ac shm ipcs -m
379
+
$ sudo ipcs -m
380
+
381
+
------ Shared Memory Segments --------
382
+
key shmid owner perms bytes nattch status
383
+
0x0000162e 0 root 666 27 1
384
+
```
385
+
313
386
## Linking Containers
314
387
315
388
The link feature allows multiple containers to communicate with each other. For
0 commit comments