I have a project with 3 docker containers/services: Blazor WASM client, Asp.Net Core API and a Postgres DB. I have set up SSL in Nginx and can reach the client without issues. All containers appear to run fine, and no errors are being thrown during docker-compose build. Although I try not to reach out too often, I'm really stumped by issues connecting between API and db container, with previous 502 error resolved by removing proxy reference from nginx.conf but an ongoing 405 error as the only response coming back. All db migration attempts have failed using code in Program.cs and in API Dockerfile. I can overcome this with SQL script, but still after this is done and the db/table schema is built, 405 error persisted. Any advice from those more experienced would be greatly appreciated.
Please note: the pgAdmin4 service/container was only added for troubleshooting, and is not part of the project itself - it will be removed, but I left it here in case it helps guide a potential response - no issues in connecting from pgAdmin4 to postgres container.
EDIT: Thanks to the kind contribution below, the 405 error appears resolved - currently getting a new Service worker error as follows:
"Failed to load ‘https://192.168.20.144/api/...’. A ServiceWorker passed a promise to FetchEvent.respondWith() that rejected with ‘TypeError: NetworkError when attempting to fetch resource.’.
I have also edited the code samples to include the update from the contirubition, with many thanks to Max for his time.
The relevant code segments are below:
Nginx.conf file as follows:
worker_processes 4;events { worker_connections 1024;http { sendfile on; upstream app_servers { server 127.0.0.1:7000; server 127.0.0.1:5432; }include /etc/nginx/mime.types; server { # 2 - see below listen 443 ssl; server_name 192.168.20.144; ssl_certificate /etc/nginx/certs/cert.pem; ssl_certificate_key /etc/nginx/certs/key.pem; root /usr/share/nginx/html; location / { proxy_pass http://backend:7000/api; proxy_http_version 1.1; 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; }}Docker-compose.yml file as follows:
services: frontend: build: context: . dockerfile: Dockerfile-app ports: - '80:80' - '443:443' tty: true networks: - frontend backend: build: context: . dockerfile: Dockerfile-api ports: - '7000:7000' depends_on: - database networks: - frontend - backend pgadmin: container_name: pgadmin image: dpage/pgadmin4:snapshot restart: always environment: PGADMIN_DEFAULT_EMAIL: admin@admin.com PGADMIN_DEFAULT_PASSWORD: password PGADMIN_LISTEN_PORT: 80 ports: - "8000:80" networks: - backend depends_on: - database volumes: - data:/data/db database: build: context: . dockerfile: Dockerfile-db restart: always volumes: - data:/data/db - ./cert.pem://var/lib/postgresql/cert.pem - ./key.pem://var/lib/postgresql/key.pem ports: - '5432:5432' environment: POSTGRES_PASSWORD: pass POSTGRES_USERNAME: postgres POSTGRES_DB: mpau networks: - backendvolumes: data:networks: frontend: name: custom_frontend backend: name: custom_backendDockerfile for API as follows:
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS buildARG TARGETARCHWORKDIR /source# Copy project file and restore as distinct layersCOPY --link Server/*.csproj .RUN dotnet restore -a $TARGETARCHRUN dotnet tool restoreENTRYPOINT dotnet ef database update --project ./*.csproj --connection "host=database-1 port=5432 dbname=mpau user=postgres password=pass connect_timeout=10 sslmode=prefer sslcert=<STORAGE_DIR>/.postgresql/cert.pem sslkey=<STORAGE_DIR>/.postgresql/key.pem"# Copy source code and publish appCOPY --link Server/. .RUN dotnet publish -a $TARGETARCH -o /app# Runtime stageFROM mcr.microsoft.com/dotnet/aspnet:9.0EXPOSE 8080WORKDIR /appCOPY --link --from=build /app .USER $APP_UIDENTRYPOINT ["dotnet", "wasm.Server.dll"]