Different process are running as PID 1 when running CMD/ENTRYPOINT in shell form when the base images is centos vs ubuntu:trusty

前端 未结 1 441
深忆病人
深忆病人 2021-01-06 14:52

Build and run an image using the below dockerfile.

Dockerfile1

FROM ubuntu:trusty
ENTRYPOINT ping localhost

Now run the below comm

相关标签:
1条回答
  • 2021-01-06 15:33

    This is the behavior of bash. Docker is still running the command with a shell which you can identify with an inspect:

    $ docker inspect test-centos-entrypoint --format '{{.Config.Entrypoint}}'
    [/bin/sh -c ping localhost]
    

    You can see the version of /bin/sh (note the GNU bash part):

    $ docker exec -it quicktest /bin/sh --version
    GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
    Copyright (C) 2011 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    
    This is free software; you are free to change and redistribute it.                               
    There is NO WARRANTY, to the extent permitted by law.
    

    The ubuntu version of /bin/sh (possibly dash) doesn't even support the --version flag and is not linked to bash. But if you change the ubuntu image to use bash instead of /bin/sh, you'll see the behavior matching centos:

    $ cat df.ubuntu-entrypoint
    FROM ubuntu:trusty
    ENTRYPOINT [ "/bin/bash", "-c", "ping localhost" ]
    
    $ DOCKER_BUILDKIT=0 docker build -t test-ubuntu-entrypoint -f df.ubuntu-entrypoint .
    Sending build context to Docker daemon  23.04kB
    Step 1/2 : FROM ubuntu:trusty
     ---> 67759a80360c
    Step 2/2 : ENTRYPOINT [ "/bin/bash", "-c", "ping localhost" ]
     ---> Running in 5c4161cafd6b
    Removing intermediate container 5c4161cafd6b
     ---> c871fe2e2063
    Successfully built c871fe2e2063
    Successfully tagged test-ubuntu-entrypoint:latest
    
    $ docker run -d --name quicktest2 --rm test-ubuntu-entrypoint
    362bdc75e4a960854ff17cf5cae62a3247c39079dc1290e8a85b88114b6af694
    
    $ docker exec -it quicktest2 ps -ef
    UID        PID  PPID  C STIME TTY          TIME CMD
    root         1     0  0 13:05 ?        00:00:00 ping localhost
    root         8     0  0 13:05 pts/0    00:00:00 ps -ef
    
    0 讨论(0)
提交回复
热议问题