compose: Nginx "No route to host" error

Hi! I have a web container where I run Nginx with upstream set to server app:8080;. app is a container running unicorn. When I up everything at the start it’s all working fine but if I issue a docker-compose restart app then Nginx stops being able to route to the upstream server with the error:

connect() failed (113: No route to host) while connecting to upstream

I have to also restart the web container for it to start working again. I checked the hosts file but the IP of the app container remains the same after restarting the web container.

I’m I missing some detail about how docker-compose works?

My docker-composer-yml:

dbdata:
  image: postgres:9.4.4

db:
  image: postgres:9.4.4
  volumes_from:
    - dbdata
  env_file: .env

app:
  build: .
  links:
    - db
  volumes:
    - .:/app

web:
  image: nginx:1.9
  ports:
    - '3000:80'
    - '3443:443'
  links:
    - app
  volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf
  volumes_from:
    - app

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

You have a app service but there is no such host name. Host name will look something like projectX_app_1 where 'projectX' is the name of the current dir (unless overridden). Last number will change depends on number of app containers you run

What does docker-compose ps give you, does it say that the container is running or exited? Also, try docker-compose logs <container_id> to see if something goes wrong with either Nginx or your actual application. As far as I can tell, you’re starting your containers in daemon mode, so you don’t have access to the logs. I would recommend you perform the following steps to see if anything goes wrong while your application is restarting:

  • Start the containers in daemon mode: docker-compose up -d
  • Attach to logs for both containers : docker-compose logs (in the directory where you have docker-compose.yml
  • Restart your application and see what the logs tell you.

That is why I asked you to use the logs and inspect your containers. You can use the “hostname” property in your docker-compose.yml and assign a value to it for your application and in the nginx conf use that hostname instead. Note that in production, if they are going to be on separate boxes, you will still need to have the ip in the configuration.

Best, Adrian.

On 09 Sep 2015, at 9:08 pm, bsantos notifications@github.com wrote:

Nevermind. I figured it out: I thought docker-compose would keep the same IP between runs of the same container but it changes with each restart causing the nginx.conf to become stale. I can fix it by sending a SIGHUP to nginx which will make it reload the conf file and read the updated IP from the hosts file.

I suppose there isn’t a way to tell docker or compose to keep the same IP when restarting a container?

— Reply to this email directly or view it on GitHub.

nginx only resolves hostnames on startup. You can use variables with proxy_pass to get it to use the resolver for runtime lookups.

See:

It’s quite annoying.

Nevermind. I figured it out: I thought docker-compose would keep the same IP between runs of the same container but it changes with each restart causing the nginx.conf to become stale. I can fix it by sending a SIGHUP to nginx which will make it reload the conf file and read the updated IP from the hosts file.

I suppose there isn’t a way to tell docker or compose to keep the same IP when restarting a container?