Docker httpd:alpine image exits with code 1

Viewed 2240

I am trying to run some basic html pages using httpd docker image.

Dockerfile

FROM httpd:alpine

COPY ./views /usr/local/apache2/htdocs/    # where my html pages stored

COPY httpd.conf /usr/local/apache2/conf/httpd.conf

RUN httpd -v

EXPOSE 7074

httpd.conf

ServerName localhost
Listen 7074
LoadModule mpm_event_module modules/mod_mpm_event.so

docker-compose

version: '3'

frontend_image:
    image: frontend_image
    build: 
      context: ./frontend_image
      dockerfile: Dockerfile
    network_mode: "host"
    env_file: "./api.env"
    depends_on: 
      - apigateway

Then : sudo docker-compose up --build

RUN httpd -v gives:

Server version: Apache/2.4.43 (Unix)
Server built:   Apr 24 2020 15:46:58

But

Project_frontend_image_1 exited with code 1

How can I add an Entry-point to httpd, as I do not have apachectl2 in /usr/sbin.

refered : Docker run Exited 1 httpd

Edit :

I have tried docker run -dit --name my-apache-app -p 7575:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4 and it works.

2 Answers

It seems this is a problem with httpd.conf file rather than the Docker image.

As you can run docker run -dit --name my-apache-app -p 7575:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4 and access to apache service.

Run above command and login to running container : sudo docker exec -it container_id /bin/sh

cat /usr/local/apache2/conf/httpd.conf

Copy the content and past in your httpd.conf, change port.

No need to add CMD[""] things as httpd:alpine base image does it.

Just COPY httpd.conf /usr/local/apache2/conf/httpd.conf in Dockerfile.

This is the script executed by default by the httpd alpine image:

2.4/alpine/httpd-foreground

#!/bin/sh
set -e

# Apache gets grumpy about PID files pre-existing
rm -f /usr/local/apache2/logs/httpd.pid

exec httpd -DFOREGROUND "$@"

Try and add an echo "test" before and after the rm command to check that:

  • the CMD script is actually called
  • the rm command is not the one causing an error (and an exit of the script with status 1)

docker-library/httpd issue 127 mentions a similar issue, solved with the Apache ErrorLog directive (presumably similar to one used in issue 133, with a mounted httpd-vhosts.conf.


I have tried docker run -dit --name my-apache-app -p 7575:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4 and it works.

Then modify your docker-compose.yml to include the same mount (see documentation):

frontend_image:
    image: frontend_image
    volumes:
      - ./:/usr/local/apache2/htdocs/
    build: 
      context: ./frontend_image
      dockerfile: Dockerfile
    network_mode: "host"
    env_file: "./api.env"
    depends_on: 
      - apigateway
Related