Docker — Image creation and Management

Docker is a platform where developers can run, develop and deploy container-based applications. we have images and containers in docker world. An image is an executable package that includes everything needed to run an application — the code, a runtime, libraries, environment variables, and configuration files. A Container is the running instance of the image means you can create as many containers as possible from a single image.
This article is all about Images.
Once you install docker you can check the version, info with the following commands just to make sure you installed correctly.
docker --version
docker infoAgenda
- where to start
- pulling images from docker hub
- Listing images
- Image History
- Inspecting image
- Creating an Image
- Dockerfile
- Removing images
- Sharing images
- Pushing Images
Where to start
Once you install docker in your machine, the first thing you could do is create an image or pull an image from the docker hub so that you can run the containers out of it.
Pulling images from docker hub
with the docker pull command, you can pull the image from the docker hub if it's not available in the local system. Let’s pull ubuntu.
docker pull ubuntu
docker pull ubuntu:<tag>
if you look at the above image with the first pull it actually downloads all the layers necessary to build the image from the docker hub. But, from the second time onwards it actually pulls from the local system.
by default, it will pull the latest tag. you can specify which tag you want to pull. Let’s pull the image with another tag.

Listing images
There are two ways to see the number of images that we have in the system. docker images will give all the details about the image, tag, image id, size, and created date etc.
docker images
Another way is to use docker info. But, you can only see a number of images

we can actually list only image ids with -q flag.
// list only ids
docker images -q// no truncate outout
docker images --no-trunc// usage of format
docker images --format "{{.ID}}: {{.Repository}}"
Image History
Find out the image history with the following command.
docker history <image>
docker history <image>:<tag>
Inspecting Image
you can inspect the image with the following command. you can actually see a lot of information about the image like the longest version of image id, tags, created date, instantiation command etc..
docker inspect <image>:<tag>
you can use a pipe ( | ) or — format option to obtain specific settings
docker inspect ubuntu | grep Id
docker inspect ubuntu --format "{{json .Config}}"
Creating Images
We can pull images from docker hub and we can automate creating docker images with the help of Dockerfile.
Dockerfile
A Dockerfile can be used to automate the creation of a Docker container image. Here is the detailed Dockerfile article.
Sharing Images
we can share and push changes to docker hub in the same way as Github or we can create our own private registry. Sometimes we want to share images without publishing to any repository. Here is the link for it.
Pushing Images
We can push images to docker hub or any private repository. Let’s see the example of pushing images to the docker hub. It is customary to push docker images with docker hub username <dockeruserid>/<repo-name>.
// docker login
docker login// build an image with <dockeruserid>/<repo-name>
docker build -t bbachin1/sampledocker -f Dockerfile3 .// list images
docker images// docker push
docker push bbachin1/sampledocker



Conclusion
This is enough docker for creating and managing images.
Thank you for reading and If you find this useful, Please give it a clap and help others to find it. Please follow me for more interesting stories:)
