Apache · Configuration and operations
How do you run Apache well in Docker?
Short answer
Use the official httpd image, bake configuration and content into the image, run in the foreground and log to stdout and stderr. Treat the container as immutable and keep state outside it.
The official httpd image uses /usr/local/apache2 as ServerRoot, with conf/httpd.conf, htdocs and logs underneath. The default command runs Apache in the foreground so the container stays alive. Configuration should be built into the image or injected through a controlled template, not edited by hand at runtime.
FROM httpd:2.4
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
COPY ./public/ /usr/local/apache2/htdocs/
COPY ./apache/app.conf /usr/local/apache2/conf/extra/app.conf
RUN echo 'Include conf/extra/app.conf' >> /usr/local/apache2/conf/httpd.conf
EXPOSE 80
HEALTHCHECK CMD curl -fsS http://127.0.0.1/health || exit 1Container practices
- Log to stdout and stderr so the platform handles collection and rotation
- Do not run as root if the image and port setup allow a non-root user
- Mount TLS certificates and secrets read-only, or terminate TLS at the ingress
- Keep document roots on image layers or read-only volumes, not writable containers
- Set ServerName to avoid startup warnings and unpredictable redirects
- Use a health check against a cheap endpoint, not a full application page
- Pin image tags and rebuild regularly for security patches
- Validate configuration during the build or entrypoint before starting
Apache writes pid and log files by default. In a container, redirecting logs to stdout and stderr avoids filling an ephemeral filesystem and lets the orchestrator collect them. If the image expects a writable runtime directory, mount a tmpfs or configure a writable path explicitly.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Where does the official httpd image keep its configuration?
- 2Why should Apache log to stdout in a container?
- 3How do you handle TLS certificates in containers?
- 4What should a container health check verify?
Say it in the interview
I use the official httpd image and bake configuration and content into it. Apache runs in the foreground and logs to stdout and stderr so the platform can collect them. I keep the container immutable, mount secrets and certificates read-only, and terminate TLS at the ingress where possible. Health checks hit a cheap endpoint, and I validate config before startup.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Apache mock interview and get scored feedback on depth, clarity and confidence.