How to create Images in Docker tutorial

Images

We have seen very basic stuff of docker images, now we will do a deep dive into docker images. Images are built and distributed like software. As we have seen in the Continuous Integration chapter that there should be a process of Build & Release a software, we must do the same if we are releasing Images. We have mentioned earlier Images are stopped state of a container so you can stop a container and create a new image from it.

We see from the above figure that we pull an image, run a container, customize it as per our requirement, commit the container into an image and then ship it. However, once you’ve started a container form an image, the two constructs become dependent on each other and you cannot delete the image until the last container using it has been stopped and destroyed. Attempting to delete an image without stopping and destroying all containers using it will result in errors. Images that we are shipping should be lightweight and should only contain the files and libraries that required to run the application inside it. For example, if we are shipping a java application, it should contain only java libraries, an application server like Tomcat and files to run our app and not anything extra.

Pulling Images


As you can see now we have two images downloaded on our docker engine

Image Registries

Docker images are stored in image registries. The most common image registry is Docker Hub. Other registries exist including 3rd party registries and secure on-premises registries, but Docker Hub is the default, and it’s the one we’ll use in this tutorial.
https://hub.docker.com/
Image registries contain multiple image repositories. Image repositories contain images. That might be a bit confusing, so Figure 5.2 shows a picture of an image registry containing 3 repositories, and each repository contains a few images.

Image Tags

While pulling an image we give the image name: TAG and docker will reach by default to docker hub registry and find the image with the TAG we specified.
Docker hub contains Official and unofficial repositories.
Official repositories are from Docker, Inc. These are safe and secure images with the latest up to date software.
Unofficial repositories are uploaded by anyone and are not verified by Docker, Inc. The list below contains a few of the official repositories and shows their URLs that exist at the top level of the Docker Hub namespace:
Our personal images live in the unofficial repositories. Below are some examples of images in my repositories:

Image Tags

While pulling an image we give the image name: TAG and docker will reach by default to docker hub registry and find the image with the TAG we specified. 

docker pull nginx: latest 

if we do not specify any tag then the default tag is latest. The latest tag does not mean that the images are latest in version, it’s just the name of the tag and that’s all. 

docker pull nginx 

Images and layers

All Docker images are made up of one or more read-only layers as shown below
There are a few ways to see and inspect the layers that make up an image, and we’ve already seen one of them. Let’s take a second look at the output of the docker pull node:latest command from earlier:
$ docker pull node
Using default tag: latest
latest: Pulling from library/node
ef0380f84d05: Pull complete 
24c170465c65: Pull complete 
4f38f9d5c3c0: Pull complete 
4125326b53d8: Pull complete 
a1468c06f443: Pull complete 
cb113e1791ca: Pull complete 
519ce9303f95: Pull complete 
f15f31d0549a: Pull complete 
Digest: sha256:1d496e5c8e692dfabeb1cc8a18f01e2b501111f32c3d08e94e5402daeceb94e6
Each line in the output above that ends with “Pull complete” represents a layer in the image that was pulled. As we can see, this image has 5 layers.
Each layer is only a set of differences from the layer before it. The layers are stacked on top of each other. When you create a new container, you add a new writable layer on top of the underlying layers. This layer is often called the “container layer”. All changes made to the running container, such as writing new files, modifying existing files, and deleting files, are written to this thin writable container layer. The diagram below shows a container based on the Ubuntu 15.04 image.

Comments