Getting the following nginx error when hitting localhost on the host
cron-job-server-nginx-1 | 172.18.0.2 - - [29/Mar/2023:09:56:23 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0"
cron-job-server-nginx-1 | 2023/03/29 09:56:23 [error] 22#22: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.2, server: , request: "GET / HTTP/1.1",
I’ve tried setting environment variable ASPNETCORE_URLS
to http://+:5000
but it doesn’t change anything.
There is an interesting output line from ASP.NET, but shouldn’t affect IPV4?:
cron-job-server-cron-job-server-1 | Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
docker-compose.yml:
version: '3.7'
services:
nginx:
image: nginx:stable-alpine
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- 80:80
- 443:443
restart: always
depends_on:
- cron-job-server
cron-job-server:
build:
dockerfile: Dockerfile
expose:
- 5000
Dockerfile (ASP.NET):
FROM mcr.microsoft.com/dotnet/sdk:7.0
COPY . ./application
WORKDIR /application
RUN apt-get update
RUN apt-get install mariadb-client -y
RUN cp RaspCronJobServer/appsettings.json appsettings.json
RUN dotnet build
ENTRYPOINT ["dotnet", "run", "--project=RaspCronJobServer"]
NGINX config:
user nginx;
events {
worker_connections 1000;
}
http {
server {
listen 80;
location / {
proxy_pass http://cron-job-server-cron-job-server-1:5000;
}
}
}
2
Answers
Added this to appsettings.json which fixed it:
In order to an Environment variable to take effect you need to move specify it inside a Dockerfile, e.g.: