visit
First, you need to create a new project. Let’s call it simple ‘webapp’.
Without any changes in the project, we are going to focus on the Dockerfile
. Modify it as the following example:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 as base
WORKDIR /app
EXPOSE 8080
ENV ASPNETCORE_URLS //+:8080
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY . /src
WORKDIR /src
RUN dotnet build "webapp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "webapp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "webapp.dll"]
You need to pay attention to the lines EXPOSE 8080
and ENV ASPNETCORE_URLS //+:8080
to be able to connect via HTTP to the docker container.
Build a docker image from the command line. You need to navigate to the webapp
project directory, and execute the following command:
DOCKER_BUILDKIT=1 docker buildx build --platform linux/amd64 --tag drmoz/webapp:latest .
I’m running it on Mac M1, and I have to specify --platform
parameter explicitly to be compatible with Azure deployment. I also have to activate the Docker Buildkit by specifying the DOCKER_BUILDKIT=1
parameter and using buildx
to be able to build an image for another architecture.
If you are running it on the Intel x86/x64 platform, you can use docker build
command without the need to specify --platform
parameter and activate buildx
.
You can tag your image differently, but since I’m going to use Docker Hub, I have to specify my account name: drmoz
as part of the image tag drmoz/webapp:latest
.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
drmoz/webapp latest 0cfac748256b 37 minutes ago 216MB
Let’s run the docker container to verify that the newly created image works fine. Execute docker run
command to start a container:
docker run -p 5555:8080 drmoz/webapp:latest
Specify the -p
parameter to map the 8080
port inside the container to your local machine 5555
port. Also, specify the image name to create the container. In my case, it is drmoz/webapp:latest
.
Now, you can navigate in your browser //localhost:5555
to see the ASP.NET Core Web App home page.
We need to push an image to the . Before that, you must register on the Docker Registry, and create a repository. Click on the ‘Create repository‘ button on the right corner of the home page.
Specify the Repository Name
field, and keep the repository visibility Public
.
docker login
docker push drmoz/webapp:latest
Now, we are ready to deploy our ASP.NET Core Web Application to Azure. Let’s log in to the Azure Portal, and create a new resource group. Specify the Resource Group name as ‘webapp-rg’, and click the ‘Review + create’ button.
You need to specify the Resource Group
one that we created previously. Also, specify a unique Name
for the Web App. Select ‘Docker Container’ in the Publish
field. Later, we will be able to specify which Docker image to use.
Select any suitable options in the Pricing plans
section, but I recommend using a Free F1 tire for test purposes. Navigate to the Docker tab.
On this tab, select ‘Docker Hub’ in the Image Source
field. Select ‘Public’ in the Access Type
field, and specify the Image and tag
value with the name of the image we pushed to Docker Hub. Navigate to the ‘Review + create’ tab. On this tab, click the ‘Create‘ button:
Click on the ‘Browse‘ button to open a deployed web application. If everything went correctly, you should see the ASP.NET Core Web App home page similar to the one you saw in your browser by navigating //localhost:5555
.