Layers of docker file just like, files are generated after running some command. Docker provides the different storage drivers for Linux flavored operating systems and windows.
Below are some of the drivers for Linux flavored operating systems.
- aufs (the original and oldest)
- overlay2 (probably the best choice for the future)
For windows, only one driver named windows filter supported by docker.
Docker file will create intermediate images for some of the instructions like RUN, COPY, ADD, etc. for others, it just updates the metadata of the existing image.
Each docker file will have a base image, for this base image, the docker will create a layer, and then next docker instructions will be executed based on this layer.
We can find the all docker layers in /var/lib/docker/<storage-driver> folder.
We can find the default storage driver in two ways.
$docker system info
$docker system info is the command to display a storage driver.
Or specify the storage driver in /etc/docker/daemon.json file and restart the docker to reflect the changes.
It will contain all docker layers for a specific storage driver.
Navigate to any of the folders, we can find the contents of the layer.
For suppose, execute the docker pull hello-world command.
For Linux overlay2 is the default storage driver.
Navigate to /var/lib/docker/overlay2 and do ls -al to display all files and folders. We can find some hashcode folder.
Navigate to 35bf… /diff folder to see the contents of this layer.
These layers can be re-used by multiple images to reduce the disk space, and also reducing the time to build the image.
Let's create docker build and see how these layers are generating:
Clone the https://github.com/nigelpoulton/psweb.git to generate the docker image.
Below is the docker file.
Alpine is the minimal Linux based os with mandatory commands are available and also with the small-sized docker image.
The GitHub repository is the nodejs based application, so we need to nodejs and npm tools, we are doing in the second line based on the alpine image layer, in this stage, docker creates a temporary image for this.
Means copy buildContext folder to src folder, changed the working directory to src folder, and then installing npm dependencies then starting nodejs application.
As we saw from the above command for intermediate docker image, deleting and creating of the new images.
$ docker image inspect pswed
$ docker image inspect pswed is the command to see the list of images with their locations in a JSON file.
We learned about the docker layers, how it will be formed, what are its usages, and also learned about the above docker storage driver. Docker command to get all layers for a given image, how to find the contents of this layer. Don't worry if you're stuck in a project, Hire Full Stack Java Developers team for a new and ongoing project which solve your query also guide how you can go ahead.