C
C#2mo ago
Casah

Need help with the deployment of my asp.NET core api

I'm developing a RESTApi and a websocket for a mobile app using rider. I need a mysql database, so i chose to deploy it on a container with phpmyadmin. Now that my mysql container is working I wanted to add the image of my api within it I tried to accept the certificats on my computer by using this command: dotnet dev-certs https --trust, but then i realised that it was useless because of docker. I also tried running it on release using visual studio and the app started but it was using the 7115 port instead of the 8080 one. I then tried to restart it from rider and i got the same error as previously. This error block me from adding it to my container. Please find the error, my dockerfile, and the program.cs file under. Thank you in advance PS - That dockerfile come from my deployment course in school. I understand everything in it but i may have done an error somewhere.
2 Replies
Anton
Anton2mo ago
with docker people usually do http and configure https on a gateway which redirects to your API
Casah
CasahOP2mo ago
By searching a bit, i found that i can use traefik to create a gateway so i have this docker compose file:
version: '3.7'

services:
# Ton serveur principal
vamosvamosserver:
build:
context: ./VamosVamosServer
dockerfile: Dockerfile
container_name: api
labels:
- "traefik.http.routers.api.rule=Host(`localhost`)"
- "traefik.http.services.api.loadbalancer.server.port=8080"
networks:
- web
depends_on:
- db

reverse-proxy:
image: traefik:v2.9
container_name: reverse-proxy
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.httpChallenge.entryPoint=web"
- "--certificatesresolvers.myresolver.acme.email=xxxx"
- "--certificatesresolvers.myresolver.acme.storage=/etc/traefik/acme.json"
ports:
- "80:80"
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
- web
version: '3.7'

services:
# Ton serveur principal
vamosvamosserver:
build:
context: ./VamosVamosServer
dockerfile: Dockerfile
container_name: api
labels:
- "traefik.http.routers.api.rule=Host(`localhost`)"
- "traefik.http.services.api.loadbalancer.server.port=8080"
networks:
- web
depends_on:
- db

reverse-proxy:
image: traefik:v2.9
container_name: reverse-proxy
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.httpChallenge.entryPoint=web"
- "--certificatesresolvers.myresolver.acme.email=xxxx"
- "--certificatesresolvers.myresolver.acme.storage=/etc/traefik/acme.json"
ports:
- "80:80"
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
- web
and this Dockerfile;
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["VamosVamosServer/VamosVamosServer.csproj", "VamosVamosServer/"]
RUN dotnet restore "VamosVamosServer/VamosVamosServer.csproj"
COPY . .
WORKDIR "/src/VamosVamosServer"
RUN dotnet build "VamosVamosServer.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "VamosVamosServer.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "VamosVamosServer.dll"]
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["VamosVamosServer/VamosVamosServer.csproj", "VamosVamosServer/"]
RUN dotnet restore "VamosVamosServer/VamosVamosServer.csproj"
COPY . .
WORKDIR "/src/VamosVamosServer"
RUN dotnet build "VamosVamosServer.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "VamosVamosServer.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "VamosVamosServer.dll"]
I still get the error though

Did you find this page helpful?