TIP
💡 Learn more : Azure for Containers (opens new window).
📺 Watch the video : How to Run an App Inside a Container Image with Docker (opens new window).
# Run an app inside a Container Image with Docker
# Containers for the rest of us
For some reason, I find containers are confusing and my goal with my Azure Tips and Tricks (opens new window) is to try to make things easier. In this mini-series, I'll walk you through Docker (opens new window) and how I use it with Azure. Below is a list of post that you can expect for this week.
- Azure Tips and Tricks Part 45 - Getting Started with Docker and Azure
- Today - Azure Tips and Tricks Part 46 - Run an app inside a Container Image with Docker
- Azure Tips and Tricks Part 47 - Creating a Container Image with Docker
- Azure Tips and Tricks Part 48 - Pushing a Container Image to a Docker Repo
# Create an app to run inside a Container Image with Docker
Let's continue where we left off (opens new window) in our last post, which showed how to get started using Docker. We're specifically looking at how I use Docker with Azure in these posts.
Begin by opening two tabs instances of either command prompt or terminal. In the right tab, enter the following command to see what docker images are available.
Michaels-MacBook-Pro:~ mbcrump$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
microsoft/aspnetcore-build latest c0c285a7a306 39 hours ago 1.85GB
2
3
Let's run the following command passing the run
parameter, an interactive terminal
and naming
our app and the image id
which the first couple of letters (found with the above command) is good enough.
After this command executes, I'll be inside my container.
docker run -it --name myapp c0
I can validate this by running dotnet --info
root@40bac5113803:/# dotnet --info
.NET Command Line Tools (2.0.2)
Product Information:
Version: 2.0.2
Commit SHA-1 hash: a04b4bf512
...
2
3
4
5
6
7
8
I know this because I don't have dotnet core tools installed on my Mac. Very cool! You now have a running container that has the dotnet core tools with just a couple of commands.
We could further validate this by running uname -r
or just uname
.
root@40bac5113803:/# uname -r
4.9.49-moby
root@40bac5113803:/# uname
Linux
2
3
4
Let's go ahead and create an app. Run through the following commands to create a new dotnet core console app
.
root@40bac5113803:~# mkdir myapp
root@40bac5113803:~# cd myapp
root@40bac5113803:~/myapp# dotnet new console
root@40bac5113803:~/myapp# dotnet restore
root@40bac5113803:~/myapp# dotnet run
Hello World!