Creating an image from the container
There are a couple of ways to create images, one is by manually committing layers and the other way is through Dockerfiles.As we start a new container, a read/write layer gets attached to it. This layer will get destroyed if we do not save it. In this recipe, we will see how to save that layer and make a new image from the running or stopped container using the docker commit command.
Syntax: docker commit -a|--author[=""] -m|--message[=""] CONTAINER [REPOSITORY[:TAG]]
root@Docker:~# docker run -i -t centos /bin/bash
[root@91fb5dbccd0b /]# yum install -y httpd
Loaded plugins: fastestmirror, ovl
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 156 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 166 kB 00:00:00
(3/4): base/7/x86_64/primary_db | 5.7 MB 00:00:11
(4/4): updates/7/x86_64/primary_db | 6.0 MB 00:00:13
...........
...........
As you can see, the new image is now being committed to the local repository with nskselvan/centos as a name and httpd as a tag.
we saw that while starting a container, a read/write filesystem layer will be created on top of the existing image layers from which the container started, and with the installation of a package, some files would have been added/modified in that layer. All of those changes are currently in the ephemeral read/write filesystem layer, which is assigned to the container. If we stop and delete the container, then all of the earlier mentioned modifications would be lost.
Using commit, we create a new layer with the changes that have occurred since the container started, which get saved in the backend storage driver.
root@Docker:~# docker diff 91fb5dbccd0b
C /.wh..wh.plnk
A /.wh..wh.plnk/1010.142994
.....................
A /boot/grub/splash.xpm.gz
C /etc/group
...................
C /etc/gshadow-
A /etc/httpd
A /etc/httpd/conf
A /etc/httpd/conf/httpd.conf
A /etc/httpd/conf/magic
A /etc/httpd/conf.d
...................
A /etc/httpd/conf.modules.d
We can see a prefix before each entry of the output. The following is a list of those prefixes:
A: This is for when a file/directory has been added
C: This is for when a file/directory has been modified
D: This is for when a file/directory has been deleted
For more details, please check docker commit --help
No comments:
Post a Comment