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.

  • create importable Python module in Docker container
  • Vagrant using docker as provider on MacOS, impossible to mount directory in container
  • Sharing files between container and host
  • How do you remove the deploymentConfig, image streams, etc using Openshift OC?
  • docker with pycharm 5
  • Unable to connect to docker hub from China
  • 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


    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.

  • Docker - OS X forward localhost 22 port to container 2022 port
  • How do I mount a volume in a docker container in .gitlab-ci.yml?
  • Starting bash script on Docker container startup doesn't work
  • Docker Swarm Service - force update of latest image already running
  • How to use distribute classes with Apache Spark (pyspark) & Docker
  • ENV variable isn't added correctly to the container environment
  • 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 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: set in the docker-compose of the proxy container. So the proxy container searched for the container with the environment variable 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.