I have searched for hours but I cannot find the root problem cause.This is my docker-compose.yml file you can see below:
version: "3"
services:
postgres:
image: "postgres:latest"
environment:
- POSTGRES_PASSWORD=postgres_password
redis:
image: "redis:latest"
nginx:
restart: always
build:
dockerfile: Dockerfile
context: ./nginx
ports:
- '3666:80'
depends_on:
- api
- client
api:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /app/node_modules
- ./server:/app
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- PGUSER=postgres
- PGHOST=postgres
- PGDATABASE=postgres
- PGPASSWORD=postgres_password
- PGPORT=5432
client:
stdin_open: true
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- /app/node_modules
- ./client:/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- /app/node_modules
- ./worker:/app
This is my nginx/default.conf
upstream client {
server client:3000;
}
upstream api {
server api:5000;
}
server {
listen 80;
location / {
proxy_pass http://client;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://api
}
}
When I try :
#docker-compose up –build
This error occured in the process:
nginx_1 | nginx: [emerg] host not found in upstream "api:5000" in /etc/nginx/conf.d/default.conf:6
2
Answers
please check your docker-compose file, you must set api under services
Probably there is an error in the API container when it’s trying to run, so it crashes and closes down. This results in Nginx failing to connect. Open the logs of the given container, to see what’s causing the issue.