Configure docker httpd image

Recently I had to publish multiple application on a single machine and all applications will be publicly available on their own domains names.

As I am a docker addict, I want all my applications to be running as a docker container.

Imagine I have the following applications :

name url Container Name Container Port (Expose)
app1 app1-container 3000
app2 app2-container 4000
app3 app3-container 8080

IMPORTANT: I assume that all container are running (with or without -P flag)

The thing is that I do not want to install a proxy (Apache or Nginx) on the docker host, so I wanted to create a docker container that will act as a proxy of all my applications

So I decided to use the docker httpd:2.4 image.

Create your project directory : mkdir ~/apache-proxy & cd ~/apache-proxy

Extract httpd.conf

First you will need to “extract” the httpd.conf file from the image to be able to configure your apache server.

So you need to start a docker httpd container in a terminal :

docker run -it --name apacheTmp httpd:2.4

NOTE: The name apacheTmp is just here to make extraction easy and to show you that this container will be deleted after use…

Then open a new terminal window (or a new sesion if you are doing it remotely)

And copy the httpd.conf file :

docker cp apacheTmp:/usr/local/apache2/conf/httpd.conf ~/apache-proxy

NOTE: personnaly I prefer to create a copy (to keep the original as it was) : cp ~/apache-proxy/httpd.conf ~/apache-proxy/my-httpd.conf.

Configure apache and vhosts

Now I edited the my-httpd.conf file to enable modules proxy and proxy_http,

I just remove comment on the lines :

LoadModule proxy_module modules/


LoadModule proxy_http_module modules/

Then I created, at the end of the files my 3 vhosts

    <VirtualHost *:80>
      ProxyPass / http://app1:3000/
    <VirtualHost *:80>
      ProxyPass / http://app2:4000/
    <VirtualHost *:80>
      ProxyPass / http://app3:8080/

Create Docker Container

Now I can Create my “proxy” docker file :

  • ~/apache-proxy/Dockerfile
    FROM httpd:2.4
    COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf

So I can build now :

docker build -t my/apache-proxy .

Then I can run it :

docker run -d -p 80:80 --link app1-container:app1 --link app3-container:app3 --link app2-container:app2 --name my-proxy my/apache-proxy

And now you should be able to access your 3 apps …