Consider the following Dockerfile:
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install -y apache2 && \
apt-get clean
ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]
When running the container with the command docker run -p 8080:80 <image-id>
, then the container starts and remains running, allowing the default Apache web page to be accessed on https://localhost:8080
from the host as expected. With this run command however, I am not able to quit the container using Ctrl+C
, also as expected, since the container was not launched with the -it
option. Now, if the -it
option is added to the run command, then the container exits immediately after startup. Why is that? Is there an elegant way to have apache run in the foreground while exiting on Ctrl+C
?