Skip to content

Instantly share code, notes, and snippets.

@xiaomi7732
Last active June 8, 2023 00:31
Show Gist options
  • Save xiaomi7732/9c5ecaf9306632a378699c22d84152fa to your computer and use it in GitHub Desktop.
Save xiaomi7732/9c5ecaf9306632a378699c22d84152fa to your computer and use it in GitHub Desktop.
Run an ASP.NET Web docker container

Command:

docker run -it -p localport:containerport --rm <containerTag>

Example:

docker run -it -p 8080:80 --rm dotnet-diag-webapi-example:latest

Quick points: Expose container 80 as local 8080, using --rm to delete the container once the process is terminated.

Dockerize a local publish:

  1. Run dotnet publish -c Release
  2. Build the image by copying the content of publish folder:
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY ./bin/Release/net7.0/publish .
ENTRYPOINT ["dotnet", "WebAPIExample.dll"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment