Skip to content

Taking .NET Core project to the Cloud: A Docker Deployment Journey

Docker Linux Shamsher Haider BigData

I had been working tirelessly on my cutting-edge .NET Core application, and it was finally polished and ready to conquer the world (or at least the internet). But how do I get it out there? Local testing is great, but I needed a way to deploy it securely and efficiently. That’s where Docker came in, the magical containerization tool that promised to streamline the process.

Building for the Cloud

The first step was to prepare the application for its big move. I used the dotnet publish -c Release command in my terminal. This built an optimized version of the application in a folder called published. Think of it as packing my bags for the journey:

dotnet publish -c Release

Dockerfile: The Blueprint

Next, I needed to create a blueprint for Docker to understand how to package and run ShamsherAI. So, I created a new text file named Dockerfile at the root of my project directory. This file would be Docker’s instruction manual.

I opened the Dockerfile and started filling it with my recipe. The first line, FROM mcr.microsoft.com/dotnet/aspnetcore:7.0 AS base, instructed Docker to use the official .NET Core ASP.NET Core runtime image (version 7.0 in this case) as the foundation. It’s like choosing a reliable spaceship for my application’s voyage:

FROM mcr.microsoft.com/dotnet/aspnetcore:7.0 AS base

Then, I told Docker to set the working directory within the container using WORKDIR /app. This is where my .NET app would reside once it landed on its cloud destination.

WORKDIR /app

The next line, COPY published ., was crucial. It instructed Docker to copy all the published files (my packed bags) from the published folder on my machine to the /app directory within the container. Essentially, I was loading ShamsherAI onto the spaceship:

COPY published .

To ensure the application was accessible from the outside world, I used EXPOSE 80. This exposed port 80, the standard port for web applications, so it would be like an open door for communication:

EXPOSE 80

Finally, I needed to tell Docker what to run when the container started. I used ENTRYPOINT ["dotnet", "ShamsherApp.dll"]. This line specified the command to execute (running dotnet ShamsherAI.dll) – like giving the spaceship its launch command:

ENTRYPOINT ["dotnet", "ShamsherApp.dll"]

Building the Image: Packing the Starship

With the Dockerfile complete, it was time to build the actual Docker image. I opened a terminal, navigated to my project directory, and typed the command docker build -t shamsherai .. This command instructed Docker to use the Dockerfile instructions and create a new image named shamsherai (replace with your preferred name). It was like building the spaceship based on my blueprint!

docker build -t shamsherapp .

Launching ShamsherApp into Orbit

The moment of truth arrived. I typed docker run -p 8080:80 shamsherai in the terminal. This command started a container based on the shamsherai image and mapped the host machine’s port 8080 to port 80 within the container. In simpler terms, it launched the spaceship and established a communication channel between my computer and ShamsherApp:

docker run -p 8080:80 shamsherapp

Mission Accomplished!

With a final check, I opened my web browser and typed http://localhost:8080. And there it was – ShamsherApp, running gloriously within its Docker container. I had successfully deployed my application, ready to be scaled and shared with the world!

This Docker journey was an exciting one. It allowed me to package my application efficiently, ensuring consistent behavior regardless of the environment. Now, ShamsherApp was ready to explore the vast possibilities of the cloud!