3

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.

4
  • 1
    Are there any further log messages? Why do you need it to run with network_mode: host? (This will prevent it from connecting to the apigateway container, for example, which may be related to your problem.) Commented May 17, 2020 at 17:10
  • @DavidMaze No logs, I have tried it. I have removed network_mode: host, yet problem there. I used this as its easy to connect all services from localhost with ports. Commented May 17, 2020 at 17:15
  • 1
    Try to run the docker image in interactive mode (-it) which will provide any errors if there are Commented May 21, 2020 at 10:28
  • @janitha000 I have added stdin_open: true and tty: true to my docker-compose file, yet same result. stackoverflow.com/questions/36249744/… Commented May 21, 2020 at 10:34

2 Answers 2

3
+50

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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 

10 Comments

@SachithMuhandiram As seen in github.com/docker-library/httpd/blob/…, your own Dockerfile should include COPY httpd-foreground /usr/local/bin/, with httpd-foreground modified as indicated in the answer, for testing.
@SachithMuhandiram Also, see me edit to include the missing volume in your docker-compose.yml
@SachithMuhandiram I refer to your own edit: stackoverflow.com/revisions/61853292/2. You added a volume: -v "$PWD":/usr/local/apache2/htdocs/. I propose to add the same volume in your docker-compose.yml to see if a docker-compose up will work (like your docker run command was working)
@SachithMuhandiram OK. Did you modify httpd-foreground and COPY it in your Dockerfile, in order to get some trace at runtime?
@SachithMuhandiram Since the docker run works with httpd:2.4 image, can you try the same docker run, but with the frontend_image image?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.