Building a Docker image
The .NET CLI dotnet publish
command supports creating Docker images without using a Dockerfile. However, to understand Docker, we need to know about Dockerfiles. That’s why we start building a Docker image defining a Dockerfile first.
In this section, we will do the following:
- Create a Dockerfile for the games API
- Build a Docker image using the Dockerfile
- Run the games API with a Docker container
- Create a Docker image using
dotnet publish
Creating a Dockerfile
Docker images are created using instructions in Dockerfiles. Using Visual Studio, you can easily create a Dockerfile from Solution Explorer, using Add | Docker Support. Make sure to select Dockerfile for the Container build type option. Adding a Dockerfile to the Codebreaker.GamesAPI
project creates a multi-stage Dockerfile. A multi-stage Dockerfile creates interim images for different stages.
Base stage
With the following code snippets, the different stages...