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 set WORDPRESS_DB_HOST in docker-compose
  • Docker Container/AWS EC2 Public DNS Refusing to Connect
  • How do I map volume outside C:\Users to container on Windows?
  • Why does my postgres data disappear after loading it from a backup?
  • docker hint: Error response from daemon: Get x509: certificate is valid for
  • How to add initial users when starting a RabbitMQ Docker container?
  • 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 build on Bluemix Containers can't find Dockerfile
  • Cross communication between docker containers in AWS Beanstalk
  • Can't reach ActiveMQ from inside Docker container
  • Will copying 'images' folder between machines be used to move images between docker hosts?
  • How to set docker mongo data volume
  • Why is exposing known_hosts dangerous
  • 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.