Docker run results in host not found in upstream error

I have a web application with an interface hosted in Docker. The backend already exists, but it has a "user IP address", so I had to update the local / etc / hosts file to access it. This way, from my local machine, I can access the API without any problems.

But the problem is that Docker somehow cannot resolve this "custom IP" even if the host is written in the container file (image?) / Etc / hosts.

When the Docker container starts, I see this error

$ docker run media-saturn:dev 2016/05/11 07:26:46 [emerg] 1#1: host not found in upstream "my-server-address.com" in /etc/nginx/sites/ms.dev.my-company.com:36 nginx: [emerg] host not found in upstream "my-server-address.com" in /etc/nginx/sites/ms.dev.my-company.com:36 

I am updating the / etc / hosts file using the command in the Dockerfile, for example

 # 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 "123.45.123.45 my-server-address.com" >> /etc/hosts && wget https://my-server-address.com 

When I SSH into the machine to check the current contents of / etc / hosts, the line "123.45.123.45 my-server-address.com" really exists.

Can anyone help me with this? I'm a new docker.

+5
source share
1 answer

I solved it. There are two things in the game.

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

Local workflow

  • cd to the root of the project where the Dockerfile is located
  • build image: docker build -t media-saturn:dev .
  • run the constructed image: docker run -it --add-host="my-server-address.com:123.45.123.45" -p 80:80 media-saturn:dev

Docker cloud workflow

  • Add extra_host directive to your stackfile e.g.
  • and then click Redeploy in the Docker cloud for the change to take effect.

    extra_hosts:

    • 'my-server-address.com:123.45.123.45'

Optimization tip

  • ignore as many folders as possible to speed up the process of sending data to docker deamon
  • add .dockerignore file
  • Usually you want to add folders like node_modelues , bower_modules and tmp
  • in my case, tmp contained about 1.3 GB of small files, so ignoring this speed up the process significantly
+1
source

All Articles