Docker proxy with custom networks

I am setting up a Docker server that needs to host multiple containers that need to be accessible over http (80). I followed this tutorial and this example is great for a simple situation. A proxy image used jwilder/nginx-proxy

that automates the creation of Nginx configurations when containers are configured or colored.

The problem is that all projects that will run on the Docker server use custom networks that break proxies.

Working position

The tutorial works when the proxy and web server is running bridge

on the default network . The proxy then does its job and redirects traffic to the correct container. working situation

NOT working situation

Most of the projects will be Laravel applications and consist of a web server, PHP FPM, and a database. Communication between containers is carried out through two networks; server and database.

This setting did not work with a proxy container on a bridge network. So I created a new network on the Docker server called proxy (bridge) and placed the proxy and nginx project containers in it. The proxy is now successfully configuring to include the project (ip-address: port). But when I try to access the domain I get the default Nginx welcome page. The page remains functional when the project containers are closed. The page stops working when the mediation container is stopped. The project works fine when I access the container port domain. not working situation

TL; DR;

The proxy works fine when both containers (proxy + app) are on the bridge network. The proxy gives the default Nginx welcome page when the containers are on the user's network (see images).

How can I get the proxy to work?

What have I tried?

  • Ping from proxy to project success
  • Used curl for proxy to check if webpage is working success
  • Checked Nginx proxy config file for missing details. No Correct project IP address plus port number. The file entry is identical to the example.
+3


source to share


1 answer


I found the problem through trail and error. I watched the error in the Nginx log:

2017/06/14 14:40:27 Error running notify command: nginx -s reload, exit status 1

      

So, I examined the Nginx config and saw that it has an entry for my-default-domain.com

no content in the section up. This caused the proxy to skip the reboot configuration command and thus display the default "Welcome!" Configuration. p.



The problem was that I had an environment variable DEFAULTHOST: my-default-domain.com

set in the docker-compose

proxy container. Thus, the mediation container was looking for a container with an environment variable VIRTUAL_HOST=my-default-domain.com

and could not find it in an empty empty section.

I put the default container on the network proxy

and it worked right away (or just removed the default host environment variable).

0


source







All Articles