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 Microsoft
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /source
# Copy the CSPROJ file and restore and dependencies
COPY *.sln .
COPY IQC_Database_Management_API/*.csproj ./IQC_Database_Management_API/
RUN dotnet restore
# Copy the project files and build release
COPY IQC_Database_Management_API/. ./IQC_Database_Management_API/
RUN dotnet publish -c Release -o out
# Generate runtime image
FROM mcr.microsoft.com/dotnet/sdk:7.0
WORKDIR /source
EXPOSE 5001
ENV ASPNETCORE_URLS=https://+:5001
ENV ASPNETCORE_ENVIRONMENT=Docker
COPY --from=build-env /source/out .
ENTRYPOINT [ "dotnet","IQC_Database_Management_API.dll" ]
Dockerfile frontend:
# Stage 1: Build the Angular application
FROM node:latest AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build --prod
# Stage 2: Serve the application with Nginx
FROM nginx:latest
COPY --from=build /app/dist/ESI_IQCDatabase /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["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?