Build options issue when publishing docker image

  asp.net, c#, docker, visual-studio

Visual studio runs docker with a lot of command line arguments when building/running. So hitting run in debug and release mode starts up the container with no issues.

How do I make the docker file have all the mounts and environment variables so I dont have to provide any of those when publishing the container to a container registry/repo?

My docker file looks like:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["NambaDoctorService/NambaDoctorService.csproj", "NambaDoctorService/"]
COPY ["NambaDoctorDataLayer/NambaDoctorDataLayer.csproj", "NambaDoctorDataLayer/"]
RUN dotnet restore "NambaDoctorService/NambaDoctorService.csproj"
COPY . .
WORKDIR "/src/NambaDoctorService"
RUN dotnet build "NambaDoctorService.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "NambaDoctorService.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "NambaDoctorService.dll"]

On pressing Run docker in visual studio, it starts up the image with the following commands:
Here you can see all the cmd options visual studio provides to run the container

docker build -f "C:UsersJacobsourcereposnambadoctorNamba-Doctor-ServiceNambaDoctorServiceDockerfile" --force-rm -t nambadoctorservice  --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=NambaDoctorService" "C:UsersJacobsourcereposnambadoctorNamba-Doctor-Service"
docker run -dt -v "C:UsersJacobvsdbgvs2017u5:/remote_debugger:rw" -v "C:UsersJacobAppDataRoamingMicrosoftUserSecrets:/root/.microsoft/usersecrets:ro" -v "C:UsersJacobAppDataRoamingASP.NETHttps:/root/.aspnet/https:ro" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "ASPNETCORE_HTTPS_PORT=443" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -p 80:80 -p 443:443 -P --name NambaDoctorService --entrypoint tail nambadoctorservice -f /dev/null

When I just host my container somewhere without all these cmd line options, it does not get all the mounts and command line arguments to function. I assume that all of those have to be included in my dockerfile when publishing? So how do I go about setting all those up?

For reference, this is the information provided by docker hub on inspecting the container:

Environment
ASPNETCORE_URLS
https://+:443;http://+:80

ASPNETCORE_HTTPS_PORT
443

ASPNETCORE_ENVIRONMENT
Development

ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS
true

PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

DOTNET_RUNNING_IN_CONTAINER
true

DOTNET_VERSION
5.0.2

ASPNET_VERSION
5.0.2

Mounts
/REMOTE_DEBUGGER
C:UsersJacobvsdbgvs2017u5

/ROOT/.MICROSOFT/USERSECRETS
C:UsersJacobAppDataRoamingMicrosoftUserSecrets

/ROOT/.ASPNET/HTTPS
C:UsersJacobAppDataRoamingASP.NETHttps

Ports
443/tcp
localhost:443

80/tcp
localhost:80

But when I run a the published docker image on my own:

Environment
PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

ASPNETCORE_URLS
http://+:80

DOTNET_RUNNING_IN_CONTAINER
true

DOTNET_VERSION
5.0.2

ASPNET_VERSION
5.0.2

Ports
443/tcp
localhost:443

80/tcp
localhost:80

Source: Docker Questions

LEAVE A COMMENT