Dockerfile Alpine Linux apache2 ENTRYPOINT httpd starts but container quits with no error message


I created an image using a Dockerfile.
I started the container using the command

docker run container name

The container started successfully and httpd started with a warning message for ServerName and quit.
If I manually follow the steps in the Dockerfile the httpd runs without quitting.
There is no information in the error logs.
Providing the contents of the Dockerfile

Thank you :slight_smile:


FROM alpine

RUN apk update
RUN apk upgrade
RUN apk add --no-cache apache2

RUN mkdir /run/apache2

WORKDIR /var/log/apache2
RUN touch access.log
RUN touch error.log
RUN chown root.wheel access.log
RUN chown root.wheel error.log
RUN chmod 0644 access.log
RUN chmod 0644 error.log


ENTRYPOINT ["/usr/sbin/httpd"]

I found the answer :slight_smile:

You have to start it in the foreground with the option “daemon off” in nginx,conf

The following Dockerfile just does it right

# debian-stretch-nginx

# Base Image
FROM debian

LABEL "vendor"="BroadTech Innovations PVT LTD"
LABEL "vendor.url"=""
LABEL "maintainer"=""

# Update Repository Index
RUN apt-get update

# Upgrade image and apply security updates
RUN DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -yq 

# Install Nginx
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq nginx

# Remove retrieved package files from local cache
RUN apt-get clean

# Donot daemonize Nginx
RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf

# Open port to access Nginx

# Run Nginx when container starts
CMD ["/usr/sbin/nginx"]

# --END--#

And for apache you need to run it with “-D FOREGROUND” option