Minimal configuration for reverse Apache proxy in Docker container

I am trying to configure an Ubuntu Docker container that runs the HTTP Node.js application on port 9000. To mimic the configuration of the work environment, I would also like to run Apache as a simple reverse proxy within the container that forwards this application from, say, port 80 (which I expose to a big bad world).

I managed to configure the Node.js application container, and I can install and configure Apache in my Dockerfile ; but I'm not at all new to creating a reverse proxy server, so despite the fact that Apache, of course, starts, it is not a proxy server.

My Dockerfile looks something like this:

 # DOCKER-VERSION 1.3.0 FROM ubuntu:12.04 # Install and set up Apache as a reverse proxy RUN apt-get -y install apache2 libapache2-mod-proxy-html COPY apache2.conf /etc/apache2/app.conf RUN cat /etc/apache2/app.conf >> /etc/apache2/apache2.conf RUN service apache2 start # Install and set up Node.js and bundle app # ...This works... EXPOSE 80 CMD ["./start-app.sh"] 

... where apache2.conf I add to /etc/apache2/apache2.conf :

 ServerName localhost LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass / http://localhost:9000/ ProxyPassReverse / http://localhost:9000/ 

I run this image using the following command:

 docker run -p 80:80 -p 81:9000 -d IMAGE 

I expect the switch to http://$DOCKER_HOST (i.e. the root) will be picked up by Apache and redirected to localhost:9000 (i.e. my application) in the container. (If I go to http://$DOCKER_HOST:81 , I will immediately attach to this application, just to prove that it works and works. It works.) I suspect that the problem is not with the Docker at all, but with the Apache configuration .

+5
source share
1 answer

In your Dockerfile, RUN statements define the commands that the docker-docker will execute when creating the docker image. These commands will not be executed when using the docker run .

In your case, you are trying to find a docker image that would start two processes:

  • apache server
  • nodejs server

But the start-app.sh script in CMD ["./start-app.sh"] seems to only start the nodejs server.

You cannot have a docker run to start more than one process, but you can start a process that will start others. There are different ways to achieve this; take a look at:

but more simply you can replace your CMD command with:

 CMD /bin/bash -c "service apache2 start; ./start-app.sh" 

and delete the useless RUN service apache2 start .

In your container, Docker will start one process ( /bin/bash ), which, in turn, will start apache and then run ./start-app.sh .

+6
source

Source: https://habr.com/ru/post/1205128/


All Articles