C#C
C#2y ago
Rowin ツ

Docker container not port forwarding

Hello, yesterday I was in here as well regarding some problems with my port forwarding.

Im trying to get my docker container to run on localhost:8080 and also make use of some certificates because I want to use another local project to test out the endpoints on my api which I am trying to deploy.

I have the following code

Dockerfile:
# Stage 1: Base image with HTTPS setup
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
ENV HOME=/root

USER root
WORKDIR /app
ENV DOTNET_URLS=https://+:8080
EXPOSE 8080

# Ensure the /app/certs directory exists and copy the HTTPS certificate
RUN mkdir -p /app/certs
COPY "Certs/aspnetapp.pfx" "/app/certs/aspnetapp.pfx"
RUN chown -R app:app /app/certs
USER app


# Stage 2: Build the application
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["authapi.csproj", "."]
RUN dotnet restore "./authapi.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./authapi.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Stage 3: Publish the application
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./authapi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# Stage 4: Final stage to run the application
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "authapi.dll"]

Docker-compose:
services:
  authapi:
    image: authapi:latest
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    networks:
      - authapi-network
    volumes:
      - /certs:/Certs

networks:
  authapi-network:
    driver: bridge

Appsettings:
"Kestrel": {
  "Endpoints": {
    "Https": {
      "Url": "https://localhost:8080",
      "Certificate": {
        "Path": "./certs/aspnetapp.pfx",
        "Password": "<My valid password is here>"
      }
    }
  }
},


Launchsettings:
  "profiles": {
    "https": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/public",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "https://localhost:8080"
    },
    "certificates": {
      "Default": {
        "path": "Certs/aspnetapp.pfx",
        "password": "<My valid password>"
      }
    },
Was this page helpful?