Building container images
Now that we know how to start containers and pull images, we’ll learn what should be done to create new container images. Since the image layer is immutable, you can create new images with the software of your choice to build an image by adding new layers on top of existing ones. There are two ways this can be done with Docker:
- Interactively
- Using Dockerfile
The interactive way is to create an image from an existing container. Let’s say you start a container with the Ubuntu 22.04 environment, install additional packages, and expose port 80
. To create a new image, we can use the docker
commit
command:
$ docker commit CONTAINER_ID [REPOSITORY[:TAG]]
The image name will be in the REPOSITORY:TAG
format. If no tag is given, then latest
will be added automatically. If no repository was specified, the image name will be a unique identifier (UUID). The tag, as well as the name (which is the same as the image repository’...