Creating Container Images
So far we have been using existing container images. This is nice to learn how to use them but in order to run your own workloads in containers, it is necessary to learn how to build container images yourself.
A Dockerfile describes how a container image is to be created. So let's have a first look at the container image creation workflow.
Create a working directory for the training:
mkdir workspace-ctcd workspace-ct
Create a working directory for your new container image:
mkdir 10-hello-container-worldcd 10-hello-container-world
hello-container-world working directory create a file named
Note: Visual Studio Code  offers a Docker plugin that will assist you when working with Docker including authoring Dockerfiles .
FROM busybox:1.31.1WORKDIR /appCMD ["printf", "Hello World of Containers\n"]
And run your new image:
docker image build -t hello-container-world:0.1.0 .
This will build a container local container image by the image name
hello-container-world and tag it with the tag
You should see
Hello World of Containers in your terminal.
docker run hello-container-world:0.1.0
You should see:
Hello World of Containers
Congratulations, you have built your first container image!
Summarizing the workflow above, this is what you did to create your first container image:
- Create a working directory for your container image
- Create a Dockerfile
- Build and Tag the container image from the Dockerfile
As you can see from this minimalistic example, defining a container image can be very simple.
- Microsoft Visual Studio Code, https://code.visualstudio.com/
- Visual Studio Code, Documentation, Working with Containers, https://code.visualstudio.com/docs/containers/overview