Skip to content

Instantly share code, notes, and snippets.

@johanclasson
Last active September 22, 2022 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanclasson/d0983976ff99f9e5508224035daaf617 to your computer and use it in GitHub Desktop.
Save johanclasson/d0983976ff99f9e5508224035daaf617 to your computer and use it in GitHub Desktop.

Prepare

docker system prune -a -f
az login
az account set -s "Visual Studio Ultimate med MSDN"
az group create -g demo-rg -l swedencentral
az acr create -n classon -g demo-rg -l swedencentral --sku Basic
az group delete -g demo-rg -y

Create app

dotnet new webapi -o MyApp
dotnet restore .\MyApp\MyApp.csproj
dotnet publish .\MyApp\MyApp.csproj -c Release --no-restore -o out
dotnet .\out\MyApp.dll
irm https://localhost:5001/WeatherForecast

Docker demo

https://hub.docker.com/ => Search for ".net sdk" and "asp.net core"

https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker

.gitignore and .dockerignore

**/bin
**/obj
**/out

Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:6.0 as build
WORKDIR /work
COPY ./MyApp/MyApp.csproj ./MyApp/
RUN dotnet restore ./MyApp/MyApp.csproj
COPY . ./
RUN dotnet publish ./MyApp/MyApp.csproj -c Release -o ./out

FROM mcr.microsoft.com/dotnet/aspnet:6.0 as final
WORKDIR /MyApp
COPY --from=build /work/out ./
ENTRYPOINT [ "dotnet", "MyApp.dll" ]
docker build -t my-app:latest .
docker image ls
docker run -p 8080:80 -it --rm my-app:latest
irm http://localhost:8080/WeatherForecast
docker container ls

ACR demo

docker build -t classon.azurecr.io/my-app:latest .
az acr login -n classon
docker push classon.azurecr.io/my-app:latest
docker image prune -a -f
docker run -p 8080:80 -it --rm classon.azurecr.io/my-app:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment