In my Dockerfile
, I was previously using the following CMD
so that the Apache server would launch and since it was running in the foreground, the container would remain running and I could kill it using CTRL
+ C
without issue.
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND", "-k", "start"]
I've since needed to update my Dockerfile
so that I can run another script before Apache starts so I added an entrypoint script and modified my Dockerfile
...
Dockerfile
:
...
EXPOSE 80
# Default process to run on container startup
ENTRYPOINT ["/entrypoint.d/docker-entrypoint.sh"]
# Default command to run container
CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND", "-k", "start"]
docker-entrypoint.sh
:
#!/usr/bin/env bash
# Inject Environment Variables
source ${ENTRYPOINT_FOLDER}/env.sh
# Run the main container process (from the Dockerfile CMD)
exec "$@"
In both of these updated commands I'm using the exec form of ENTRYPOINT
and CMD
, the arguments set in CMD
are to launch Apache in the foreground using the line exec "$@"
in the entrypoint script, but doing this doesn't allow me to use CTRL
+ C
any longer to quit from the terminal window.
What am I doing wrong here?
While I had used the proper exec forms for both ENTRYPOINT
and CMD
, the quit signal still wasn't working.
The resolution for this issue was to add the options -t
and -i
in my docker run
invocation.
Before:
docker run --env-file=<env-file-path> --rm -p 8080:80 ...
After:
docker run --env-file=<env-file-path> -t -i --rm -p 8080:80 ...
Reference: https://github.com/moby/moby/issues/2838#issuecomment-29205965
I also wanted to give a thank you to CharlesDuffy for helping me with this issue, I learned some things from you regarding debugging bash scripts. 👍