(I know others have asked this question before, but I'm not able to solve the problem using the solutions proposed in other posts, so i figured i would try to post my configuration files and see if someone could help.)
I want to create a container for nginx, and use proxy_pass
to pass requests to the container with the running web application. I can't figure out how to communicate between the two containers. When i try to run docker stack deploy -c docker-compose.yml somename
, only the web container starts. The nginx container fails to start, and is stuck in a loop of trying to restart. This is the log messages I get:
2017/08/16 14:56:10 [emerg] 1#1: host not found in upstream "web:8000" in /etc/nginx/conf.d/nginx.conf:2 nginx: [emerg] host not found in upstream "web:8000" in /etc/nginx/conf.d/nginx.conf:2
I found an answer that as long as you use the same name as under services in the docker-compose.yml
file, nginx would find the variable. However that doesn't seem to help in my case.
How does communication like this between different containers work? Where is the 'web' variable
Most examples I've seen use version: "2"
in the docker-compose.yml
file, should this make a difference?
My docker-compose.yml:
version: "3"
services:
web:
image: user/repo:web
deploy:
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "8000:80"
networks:
- webnet
nginx:
image: user/repo:nginx
ports:
- 80:80
links:
- web:web
depends_on:
- web
networks:
webnet:
Nginx config:
upstream docker-web {
server web:8000;
}
server {
listen 80;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://docker-web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}