Build options issue when publishing docker image

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 ["Service/Service.csproj", "Service/"]
COPY ["DataLayer/DataLayer.csproj", "DataLayer/"]
RUN dotnet restore "Service/Service.csproj"
COPY . .
WORKDIR "/src/Service"
RUN dotnet build "Service.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Service.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:UsersJacobsourcereposServiceDockerfile" --force-rm -t service  --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=Service" "C:UsersJacobsourcereposService"

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 Service --entrypoint tail service -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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Afaik, volumes can only be mounted when starting a container. So this can be either using docker run -v option or in a docker compose file. Volumes cannot be defined in a docker file.

Environment variables can defined in docker file using ENV instruction and/or with docker run command.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x