A Helpful Apache/PHP Docker Container

I ran into this issue recently where I needed to run Apache and PHP bundled in a single container, but I didn’t want to keep opening a shell in the container to get the logs.

This container exists here: https://gitlab.com/dxcker/aphpche

The Image

Dockerfile

FROM alpine:3
RUN  apk add apache2 php php-apache2 php-pdo php-pdo_mysql
ENTRYPOINT ["/usr/bin/httpd"]
CMD ["-DFOREGROUND", "-edebug"]

Let’s break this down:

FROM tells you to base this image off alpine:3. RUN will install the required Apache2 and PHP software, and PHP modules. ENTRYPOINT is set to the HTTPD executable so that the container runs that on startup. CMD is used so that you can specify your own options for httpd if you run into a situation where that is needed. Two options have been provided:

-DFOREGROUND tells httpd to run in the foreground. This is required because that’s how we run things in Docker; background services aren’t encouraged in this context, and httpd was originally designed as a background process. -edebug tells httpd to print all logs to stdout. Typically this is debug, but in our case it’s just so that we can get some information out of the stdout of the docker container. This allows us to do something like docker logs <name> and get the logs of the running container.

Jacob
Jacob

Something About Me With Multiple Lines And Markdown