As in the previous blog, we came to know about Docker and its role in DevOps and why it's used and how it's used with the help of tables and diagrams. In this section, we will be visiting some of the topics from the previous blog as well as discussing more on containers, images, docker-hub and the architecture of containers/docker.
Docker Hub
Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your Docker-built images to the Docker hub.
- We can visit the docker hub at: hub.docker.com
Next signup for a new account or sign in if you are already a user.
After you sign in you will be guided to a dashboard, for me as I have pushed some of my images on the docker hub it is showing those, for you it might or might not be empty depending on your use
Click on the explore button on the navbar to view the community images that consist of docker-verified images from official publishers, it will have more filter options on the sidebar so that you can filter and find the image you are looking for
You can view any image by clicking on them and it will have a docker pull command to pull the image to your local system/environment, you are working on, we will discuss this command later on, but first, let's know more about docker hub and other important stuff.
This image will have more properties like its name, its tags, versions, what this image contains and is used for and more other important data that will help us to select the appropriate base image for our services to be started on.
Images
In Docker, everything is based on Images. An image is a combination of a file system and parameters. Letโs take an example of the following command in Docker.
docker run hello-world
The Docker command is specific and tells the Docker program on the Operating System that something needs to be done.
The run command is used to mention that we want to create an instance of an image, which is then called a container.
Finally, "hello-world" represents the image from which the container is made.
The docker run hello-world command first finds the hello-world image locally on the system and if there isn't any image locally it goes to the docker hub and then pulls a docker image of hello-world and then it starts a container from that image as we specified a docker run command.
Here we can see how the images are being pulled with the help of the docker daemon(server) from the docker hub registry this image is the base of the container that has all the configurations and hardware requirements for starting a container.
So when the docker run command is listed it will start a container by creating a filesystem snapshot of the image and then using this snapshot to build a container that has some processes running on it.
Suppose we are running a Redis server using the docker run command
docker run redis
Then the docker daemon will first download the image from the registry(if not available locally) and then place the filesystem snapshot into that container and start a Redis server with a command(if prebuilt), some images have predefined commands that execute when the container is started, that can be overridden.
Containers
The docker containers are a type of instance that run applications, and processes and make it easy for us to make the applications scalable, reliable and available which means higher availability.
These containers have a thing commonly called a Base image, which is the main OS/kernel of the container that communicates with the internal system to run a process proeprly.
Some docker images commands
To list all the images on the sysetm
docker images
This command is used to display all the images currently installed on the system.
To remove a docker image
docker rmi (image-id)
Image-id โ This is the ID of the image which needs to be removed, the output returned will be the image-id itself that has been removed.
To list the image's id only
docker imaegs -q
To inspect an image repository
docker inspect (repository/image) ex: docker inspect hello-world
Some docker container commands
To start/run a container from an image
docker run (image-name/image-id)
To list all the running containers
docker ps
To list all the containers ever created on the system, both running and stopped
docker ps -a
To find all the commands executed on an image
docker history (image-id/iamge-name)
This was a brief overview of Docker: Hub, images and containers and some of its commands for pulling images from docker hub, starting a container, listing containers and images, etc.
In the further section, we will be talking more about Docker commands that enable us to configure deploy and monitor our containers and microservices applications around it.
Want to learn and explore more about Docker? Then do check out the Docker blog series
Hop into the blog section for a more interesting and detailed overview of Software development and other stuff. ๐