83
CHAPTER 4 | Development process for Docker-based applications
Step 3. Create your custom Docker images and embed your
application or service in them
For each service in your application, you need to create a related image. If your application is made up
of a single service or web application, you just need a single image.
Note that the Docker images are built automatically for you in Visual Studio. The following steps are
only needed for the editor/CLI workflow and explained for clarity about what happens underneath.
You, as a
developer, need to develop and test locally until you push a completed feature or change to
your source control system (for example, to GitHub). This means that you need to create the Docker
images and deploy containers to a local Docker host (Windows or Linux VM) and run, test, and debug
against those local containers.
To create a custom image in your local environment by using Docker CLI and your Dockerfile, you can
use the docker build command, as in Figure 5-5.
Figure 5-5. Creating a custom Docker image
Optionally, instead of directly running docker build
from the project folder, you can first generate a
deployable folder with the required .NET libraries and binaries by running
dotnet publish
, and then
use the
docker build
command.
This will create a Docker image with the name
cesardl/netcore-webapi-microservice-
docker:first
.
In this case,
:first
is a tag that represents a specific version. You can repeat this step
for each custom image you need to create for your composed Docker application.
When an application is made of multiple containers (that is, it is a multi-container application), you
can also use the
docker-compose up --build
command to build all the related images with a single
command by using the metadata exposed in the related docker-compose.yml files.
You can find the existing images in your local repository by using
the docker images command, as
shown in Figure 5-6.
Figure 5-6. Viewing existing images using the docker images command
84
CHAPTER 4 | Development process for Docker-based applications
Dostları ilə paylaş: