I try to run nginx in docker and connect it to one service in docker as well. Another service is running without docker and use this nginx too. My docker-compose:
version: "3.9"
services:
nginx:
restart: always
image: nginx
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "3000:80"
- "9000:81"
web:
restart: always
image: "xxxx/xxxx/web"
And nginx conf at ./config/nginx.conf
:
events {}
http{
upstream ws-api {
server host.docker.internal:8081;
}
upstream ws-web {
server web;
}
server {
server_name localhost;
listen 80;
location / {
include fastcgi_params;
fastcgi_split_path_info ^(/)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_pass ws-api;
}
}
server {
server_name localhost;
listen 81;
location / {
include fastcgi_params;
proxy_pass http://ws-web;
}
location /api {
rewrite ^([^.]*[^/])$ $1/;
rewrite ^/api(.*)$ $1 break;
include fastcgi_params;
fastcgi_split_path_info ^(/)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_pass ws-api;
}
}
}
When I open localhost:9000 I get the error message:
lookup ws-web on 192.168.65.5:53: no such host
localhost:3000 works fine
What is my mistake?
2
Answers
Updating Docker to the latest Apple Silicon Preview release fixed it for me.
Here
Not strictly on the topic. But i faced this magic IP in response while connecting my nginx services in minikube (docker VM). And was wrong expecting service domain name to be resolved by minikube’s DNS into full IP:PORT address. So, point is to add PORT:
domain_name:8888;
in proxy_pass for example.