I have two containers, one is backend developed in .Net Core and another one is frontend developed in Angular and using Nginx to forward. Currently they are well deployed and can be accessed via HTTP. Now I have the requirement to set access via HTTPS. So I changed some files.
Dockerfile .Net Core
# Get Base .NET Core SDK Image from MicrosoftFROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-envWORKDIR /source# Copy the CSPROJ file and restore and dependenciesCOPY *.sln .COPY IQC_Database_Management_API/*.csproj ./IQC_Database_Management_API/RUN dotnet restore# Copy the project files and build releaseCOPY IQC_Database_Management_API/. ./IQC_Database_Management_API/RUN dotnet publish -c Release -o out# Generate runtime imageFROM mcr.microsoft.com/dotnet/sdk:7.0WORKDIR /sourceEXPOSE 5001ENV ASPNETCORE_URLS=https://+:5001ENV ASPNETCORE_ENVIRONMENT=DockerCOPY --from=build-env /source/out .ENTRYPOINT [ "dotnet","IQC_Database_Management_API.dll" ]
Dockerfile frontend:
# Stage 1: Build the Angular applicationFROM node:latest AS buildWORKDIR /appCOPY package.json package-lock.json ./RUN npm installCOPY . .RUN npm run build --prod# Stage 2: Serve the application with NginxFROM nginx:latestCOPY --from=build /app/dist/ESI_IQCDatabase /usr/share/nginx/htmlCOPY nginx.conf /etc/nginx/nginx.confEXPOSE 80CMD ["nginx", "-g", "daemon off;"]
nginx.conf:
worker_processes 1;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; } location /api/ { proxy_pass https://iqc-api-container2:5001/api/; } error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }}
launchSettings.json in .Net Core:
{"profiles": {"http": {"commandName": "Project","launchBrowser": true,"launchUrl": "swagger","environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development" },"dotnetRunMessages": true,"applicationUrl": "http://localhost:5069" },"https": {"commandName": "Project","launchBrowser": true,"launchUrl": "swagger","environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development" },"dotnetRunMessages": true,"applicationUrl": "https://localhost:7213;http://localhost:5069" },"IIS Express": {"commandName": "IISExpress","launchBrowser": true,"launchUrl": "swagger","environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development" } },"Docker": {"commandName": "Docker","launchBrowser": true,"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}","environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Docker" },"publishAllPorts": true,"useSSL": true,"httpPort": 5000,"sslPort": 5001 } },"$schema": "https://json.schemastore.org/launchsettings.json","iisSettings": {"windowsAuthentication": false,"anonymousAuthentication": true,"iisExpress": {"applicationUrl": "http://localhost:56246","sslPort": 44369 } }}
When I try docker run in the remote server, the container fails to launch. The command I used is sudo docker run -d -v /home/qq/IQC_Database.db:/source/IQC_Database.db -p 7213:5001 --name iqc-api-container2 iqc-api2
Could someone help point out where I did wrong?
Update:
I have changed the nginx.conf to:
worker_processes 1;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name azeu1-eng-leon1.company.com; location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; } listen 443 ssl; ssl_certificate /etc/nginx/certs/server.crt; ssl_certificate_key /etc/nginx/certs/server.key; error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }}
And run the command openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout certs/server.key -out certs/server.crt -subj "/CN=azeu1-eng-leon1.company.com
and move the server.crt and server.keys to the containers /etc/nginx/certs folder. Then I restart the container but still I cannot access to the page VIA HTTPS.