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.

  • Docker container on Marathon doesn't finish
  • Bluemix Kubernetes docker deployment query
  • Error checking context is accessible: 'can't stat '.gvfs''. Please check permissions and try again
  • Backing up data volume containers off machine
  • Using shared runners to access the gitlab registry
  • docker, --storage-opts and aufs storage-driver
  • 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.

  • Connecting an Oracle DB Container and a Java application Container (Docker)
  • boot2docker is autoupgrading
  • Can't Access Spring Boot API in docker container
  • How to use run deck service from local browser using up address?
  • Jenkins: running build does not provision docker slave
  • Simple HTTP proxy / routing for my docker containers?
  • 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.