Open In App

Microsoft Azure – Running an App inside a Docker Container Image

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we’ll learn how to run an app inside of a container with Docker. For this, you need to set up Docker on your local Dev machine, by going to docker.com, and installing the Docker desktop application for your specific operating system. We can use the Docker Pokemon to pull an image from the Docker Hub onto your local machine. 

Here, we’re going to use that same image to create a running container. We will open up our command line terminal and start by typing in the Docker images command. 

docker images

This should list all of the available images that are on our machine, and this should include that microsoft/asp.netcore-build image

Now we are going to execute another Docker command to run that image:

docker run -it --name myapp microsoft/aspnetcore-build

And this is going to signal to the Docker client that we actually want to run this image in a container. The  -it is used to specify that we want to engage with the container using an interactive terminal. Then we have given our image a name. We’re going to call this “Myapp”. The last thing we need to do is specify the name of the image we want to use to create this container.

 In no time at all, our container has been started, and we’re now connected to it by an interactive terminal. 

So, since this is a.NET container, we should be able to use the below command:

 dotnet --info

It gets some info about the.NET command-line tools, that SDKs that are available.

We can also type in uname -r, and this should give us some information about the operating system and Kernel. Since we are running on a Linux container. 

Next, let’s actually create a.NET application. So, first thing we’ll do is we’ll create a folder. We’ll call this “Myapp”. 

Next, we’ll type in dotnet new and the type of application we want to create. So, in this case, we want to create a new console application. 

Now, all we need to do is type dotnet run, and as expected it prints out “Hello world!” from the script because that’s really all our simple console application is doing. 

So, you’ve just seen how easily we could create a container based on an image that we have on our local Dev machine, and create a running application inside of it.


Last Updated : 31 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads