Unable to start httpd:latest image: httpd-foreground cannot find httpd

Ubuntu Server 20.04 + docker (latest in repository)

I have created a Dockerfile for Perl/httpd:

FROM httpd:latest
RUN apt-get update && apt-get -y install \
    libapache2-mod-perl2 \
    libemail-sender-perl \
    libemail-simple-perl \
    libemail-valid-perl \
    libfile-finder-perl \
    libcgi-pm-perl \
    libtry-tiny-perl \
    libfile-fcntllock-perl \
    libjson-perl \
    libdatetime-locale-perl \
    perl

and an override for httpd.conf, including:

Listen 80

<IfModule !mpm_prefork_module>
    LoadModule cgid_module modules/mod_cgid.so
</IfModule>

DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<Directory "/usr/local/apache2/cgi-bin">
    AllowOverride None
    Require all granted
    Options +ExecCGI
    AddHandler cgi-script .pl
</Directory>

and docker-compose.yml:

version: "3"

  volumes:
    web:
      external: true

  services:
    apache-perl:
      image: apache-perl
      restart: always 
      ports:
        - 80:80
    volumes:
      - web:/usr/local/apache2:rw
      - ./wp_ports.conf:/usr/local/apache2/ports.conf:ro
      - ./httpd-foreground:/usr/local/bin/httpd-foreground:ro
      - /opt1/bitnami-wordpress/apache2/htdocs:/usr/local/apache2/htdocs:ro
      - /opt1/bitnami-wordpress/apache2/cgi-bin:/usr/local/apache2/cgi-bin:ro
      - /opt1/wordpress-bitnami/apache2/logs:/usr/local/apache2/logs:rw

and all my *.pl and *.cgi files in the cgi-bin folder have the execute attribute.

Note that all 3 containers should have the same URL, but with different ports.

Why do I get the following message?

This site can’t be reached hollandnumerics.org.uk refused to connect. Try: Checking the connection Checking the proxy and the firewall ERR_CONNECTION_REFUSED

and now I have found the following message in the apache-perl container log:

{"log":"/usr/local/bin/httpd-foreground: 7: exec: httpd: not found\n","stream":"stderr","time":"2025-03-11T11:56:35.356895565Z"}

So where should httpd be found? I have also tried /usr/local/bin/httpd and /usr/local/apache2/bin/httpd.

…Phil

I forgot to include the httpd-foreground script I am using, which was copied from https://github.com/docker-library/httpd/tree/master/2.4:

#!/bin/sh
set -e

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

exec httpd -DFOREGROUND "$@"

It would be where you expected it to be:

docker run -ti --rm --entrypoint sh httpd:latest -c 'which httpd'
/usr/local/apache2/bin/httpd

But this volume mapping mounts the named volume web in the /usr/local/apache2 folder of the container, and thus is a mount point that eclipses all content of /usr/local/apache2 with whatever exists in the web volume.:

You need to make sure that /usr/local/apache2/bin/ is not affected by your volume mapping. Right now it is.

1 Like