Last active
March 19, 2023 22:34
-
-
Save mikerochip/0705f53d82ce3068d19fc6251ce2b34a to your computer and use it in GitHub Desktop.
ASP.NET 7 Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# directories | |
**/bin/ | |
**/obj/ | |
**/out/ | |
# files | |
Dockerfile* | |
**/*.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker build --pull --build-arg AspEnvironment=Development -t asp-api-test-dev . | |
docker run --rm -it -p 8000:80 asp-api-test-dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker build --pull --build-arg AspEnvironment=Production -t asp-api-test-prod . | |
docker run --rm -it -p 8000:80 asp-api-test-prod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference: https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile | |
# with ENV and ARG modifications | |
# build stage | |
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS sdk | |
WORKDIR /source | |
# copy csproj and restore as distinct layers | |
COPY *.csproj . | |
RUN dotnet restore --use-current-runtime | |
# copy everything else and build app | |
COPY . . | |
RUN dotnet publish -c Release -o /app --use-current-runtime --self-contained false --no-restore | |
# run stage | |
FROM mcr.microsoft.com/dotnet/aspnet:7.0 | |
WORKDIR /app | |
COPY --from=sdk /app . | |
# ASP env vars must exist here since this is the run stage and these are runtime env vars | |
ARG AspEnvironment=Development | |
ENV ASPNETCORE_ENVIRONMENT=$AspEnvironment | |
RUN echo "ASPNETCORE_ENVIRONMENT=$AspEnvironment" | |
ENTRYPOINT ["dotnet", "ApiTest.dll"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment