Hi folks, I’m struggling to work this out and can’t find the magic sauce
If I use the official
httpd:latest image, it runs in the foreground and I can kill it with ctrl-c. Quick and smooth.
If I build my own image, set up the same way, ctrl-c does not work. I’ve tried to emulate the
httpd image’s basics, but it’s not working for me. Not having a ‘polite’ container is annoying to work with and also slows down iteration.
Simplifying my dockerfile to just the basics:
FROM debian:bullseye-slim RUN apt-get update \ && apt-get install --yes \ apache2 COPY --chmod=755 httpd-foreground /usr/local/bin/httpd-foreground #CMD httpd-foreground CMD [ "httpd-foreground" ] #CMD [ "apache2ctl", "-D", "FOREGROUND" ]
The httpd-foreground script is pulled from
httpd:latest, and updated only to switch the name of the launch item (
httpd binary →
Whether I use the direct command (
apache2ctl wrapper script) or the cloned launch script (
httpd-foreground), or the script in ‘array’ format (
["httpd-foreground"]), the ctrl+c function does not work.
I can’t see any meaningful difference when I docker inspect the two images - there are differences, but not in things I thought would be relevant. I also tried adding
STOPSIGNAL SIGWINCH (
httpd has this) but that didn’t work either - the custom build ignores it and does not exit when I resize the terminal.
Extra puzzling is that looking at the Dockerfile for
httpd, we’re both using
debian:bullseye-slim as a base. Both images are using a launch script (
apache2ctl is a wrapper script, as is
httpd-foreground) rather than calling the binary directly. The httpd dockerfile is here for reference
What am I doing wrong here? How do I get the container gracefully accepting a SIGINT/ctrl-c and shutting down?