Docker run results in “host not found in upstream” error

I have a frontend-only web application hosted in Docker. The backend already exists but it has “custom IP” address, so I had to update my local /etc/hosts file to access it. So, from my local machine I am able to access the backend API without problem.

But the problem is that Docker somehow can not resolve this “custom IP”, even when the host in written in the container (image?) /etc/hosts file.

  • How to re-add a container in Bluemix
  • Node container fails to run using docker for windows
  • Couldn't find repository in docker-registry-frontend
  • Sporadic Robolectric test failures when running inside Docker container
  • Enable SSL on GitLab with Docker on Synology NAS
  • Unable to pull private repo in docker
  • When the Docker container starts up I see this error

    $ docker run media-saturn:dev
    2016/05/11 07:26:46 [emerg] 1#1: host not found in upstream "" in /etc/nginx/sites/
    nginx: [emerg] host not found in upstream "" in /etc/nginx/sites/

    I update the /etc/hosts file via command in Dockerfile, like this

    # install wget
    RUN  apt-get update \
      && apt-get install -y wget \
      && rm -rf /var/lib/apt/lists/*
    # The trick is to add the hostname on the same line as you use it, otherwise the hosts file will get reset, since every RUN command starts a new intermediate container
    # it has to be https otherwise authentification is required
    RUN echo "" >> /etc/hosts && wget 

    When I ssh into the machine to check the current content of /etc/hosts, the line “” is indeed there.

    Can anyone help me out with this? I am Docker newbee.

  • New to mesos/marathon. How to deploy a new self defined docker?
  • Pass environment variable from linux to docker container
  • Extending base WordPress docker image to download latest wp-content folder
  • Docker for Mac Container to Host Networking - Consul Health Checks Connection Refused
  • Vagrant+Docker: The container started never left the “stopped” state
  • AspnetPublishHandler with name “Custom” was not found when publishing ASP.NET 5 project to Docker
  • One Solution collect form web for “Docker run results in “host not found in upstream” error”

    I have solved this. There are two things at play.

    One is how it works locally and the other is how it works in Docker Cloud.

    Local workflow

    • cd into root of project, where Dockerfile is located
    • build image: docker build -t media-saturn:dev .
    • run the builded image: docker run -it --add-host="" -p 80:80 media-saturn:dev

    Docker cloud workflow

    • Add extra_host directive to your Stackfile, like this
    • and then click Redeploy in Docker cloud, so that changes take effect


      • ‘’

    Optimization tip

    • ignore as many folders as possible to speed up process of sending data to docker deamon
    • add .dockerignore file
    • typically you want to add folders like node_modelues, bower_modules and tmp
    • in my case the tmp contained about 1.3GB of small files, so ignoring it sped up the process significantly
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.