Docker proxy with custom networks

I’m setting up a Docker server which has to host multiple containers that need to be accessible through http (80). I have followed this tutorial and the example works perfect for the simple situation. The proxy image used is jwilder/nginx-proxy which automates the creation of the Nginx configurations when containers are set up or teared down.

The problem is that all the projects that will run on the Docker server use custom networks which breaks the proxy.

  • how to create docker overlay network between multi hosts?
  • org.apache.http.conn.UnsupportedSchemeException: unix protocol is not supported
  • docker add extract to custom directory
  • how to choose pxe setup in deploying OPNFV ARNO via Fuel (master node)?
  • Docker & PostgreSQL : can not create database having '-' in database name during initilization
  • How to move Docker data folder on macOS Sierra
  • The working situation

    The tutorial way works when the proxy and the web server runs on the default bridge network. Then the proxy does his work and redirects the traffic to the correct container.
    working situation

    The NOT working situation

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

    This setup didn’t work with the proxy container on the bridge network. So I created a new network on the Docker server named proxy (bridge) and placed the proxy and project’s nginx containers in it. The proxy server now successfully changes to the configuration to include the project (ip address:port). But when I try to access the domain then I get the default Nginx welcome page. The page remains working when the project containers are shut down. The page stops working when the proxy container is stopped.
    The project is working fine when I access the domain with the containers port.
    not working situation

    TL;DR;

    The proxy is working fine when both containers (proxy + app) are on the bridge network. The proxy gives a default Nginx Welcome page when the containers are in a custom network (see images).

    How can I make the proxy work?

    What did I try?

    • Ping from proxy to project success
    • Used curl on proxy to project to check if webpage was working success
    • Checked proxy’s Nginx config file for missing details. None Project container’s IP address plus port number are correct. File entry is identical to that of the example’s case.

  • How to test Ansible playbook using Docker
  • I keep getting a 404 error when trying to push to my private repository. Why?
  • Iterate in RUN command in Dockerfile
  • Installed gems not found by bundler when BUNDLE_PATH changed with Docker
  • Run elasticsearch with docker
  • Cannot delete files on docker host
  • One Solution collect form web for “Docker proxy with custom networks”

    I found the problem through trail and error. I had overseen an error in the Nginx log:

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

    So I investigated the Nginx configuration and saw that there was an entry for my-default-domain.com in it without content in the upstream section. This caused the proxy to skip the reload config command and thus showed the default config’s “Welcome!” page.

    The problem was that I had the environment variable DEFAULTHOST: my-default-domain.com set in the docker-compose of the proxy container. So the proxy container searched for the container with the environment variable VIRTUAL_HOST=my-default-domain.com set and couldn’t find it resulting in the empty upstream section.

    I put the default container into the proxy network and it worked right away (or just remove the default host environment variable).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.