I'm trying to build container for openshift. One of their requirements is that the main process is pid 1. In order to so your starting shell script should use exec to replace the shell script. For our application we are using Tomcat, so I have no chance to replace the catalina.sh properly but to use it, as it does use exec, but the command does not get replaced. So I simplified the the container down, and the problem still persists: Dockerfile:
FROM ubuntu:18.04
ADD test.sh /root/test.sh
RUN chmod a+x /root/test.sh
CMD /root/test.sh
test.sh
#!/bin/bash
exec /bin/sleep 3600
I build the container with docker build -t test .
If I now run the container with docker run --name test-ub test and then execute docker top test-ub -ef it shows:
UID PID PPID C STIME TTY TIME CMD
root 109019 108989 0 16:50 ? 00:00:00 /bin/sh -c /root/test.sh
root 109057 109019 0 16:50 ? 00:00:00 /bin/sleep 3600
Two Processes which should not be the case! If I replace the FROM ubuntu:18.04 with FROM centos:centos7 it works as expected, only one process:
UID PID PPID C STIME TTY TIME CMD
root 105946 105916 0 16:19 ? 00:00:00 /bin/sleep 3600
So I think the problem lies somewhere in Ubuntu, but I have no idea where. Any help is appreciated.
1 Answer
I found the same question with good answer on stackoverflow.
I don't want to duplicate the answer, just give a short abstract:
The difference is between the default sh, which is dash in Ubuntu and bash in CentOS.
If you run your command with bash it will work as expected:
CMD ["/bin/bash", "/root/test.sh"]