Assume this simple Dockerfile:
FROM debian:stretch COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod a+x /usr/local/bin/entrypoint.sh ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] And entrypoint.sh looks like this:
#!/bin/bash echo yyyyyyyyyyyyyyy exec "$@" Now if I build the image and create the container in foreground, the entrypoint script is executed:
$ docker build . -t mytest [...] $ docker run --rm -it mytest /bin/bash yyyyyyyyyyyyyyy root@3e3d7290b09c:/# But if I create the container in detached mode, it is not executed:
$ docker run --rm -d -it mytest /bin/bash f8e72a222c5194f61843569ae76798bb09736fa4205b93e484f11de32df4db64 Why is that? Or, more importantly, how can I create a detached container, where the entrypoint script is executed?
-aflag. Try passing that-awhen you are in-dmode, you will be met with an error. Being in detached mode, your process is running in the background and is not outputting to your stdout.docker logs f8e72a22you should see the output of your container, starting with yourechostatement.logscommand - that's a great one!