Search code examples
dockerdocker-swarm

docker host pid mode doesn't work in swarm mode


I want a container to share PID namespace with host OS and I found host PID mode in docker.

pid

pid: "host"

Sets the PID mode to the host PID mode. This turns on sharing between container and the host operating system the PID address space. Containers launched with this flag will be able to access and manipulate other containers in the bare-metal machine’s namespace and vise-versa.

Referenced from https://docs.docker.com/compose/compose-file/#pid

It seems to work with docker run and docker-compose up but swarm mode, for example

$ docker run ---detach --pid=host ubuntu:16.04 tail -f /dev/null
$ docker exec -it container_name top
# Return all processes within host OS namespace.

##docker-compose.yml##
version: '3.4'

services:
    test:
        image: ubuntu:16.04
        command: tail -f /dev/null
        pid: host

$ docker-compose -f docker-compose.yml up -d
$ docker exec -it container_name top
# Return all processes within host OS namespace.

# there is only one manager node in the swarm(no another worker).

$ docker stack deploy -c docker-compose.yml test
$ docker exec -it container_name top 
# Return only container process namespace.

I know some options could not work as to swarm mode. However, in such case, as I know, the docker document always specify that, for instance, container_name option(See it is specifying that container_name won't work in swarm mode.).

container_name

.....

.....

Note: This option is ignored when deploying a stack in swarm mode with a (version 3) Compose file.

My docker environment is Docker 17.09.0-ce, docker-compose 1.17.0 on Ubuntu16. why doesn't pid mode work in swarm mode?


Solution

  • Finally, I opened an issue on github and I got the answer.

    https://github.com/docker/docker.github.io/issues/5624