How to start, stop and pull docker image in linux?

What is a Docker Image?

Future Techno India
6 min readFeb 6, 2022

Docker images are read-only templates used to create containers. For the container to start, we need an image. Docker hub has a lot of pre-built images. The Dockerfile and the command “docker build” can also be used to build your own custom image.

Docker / Future Techno India

Lat’s start,

List of Downloaded images

A list of all top-level images, their repository, tags, and size will appear in Docker images by default.

As an intermediate layer between the docker image and the docker build, allowing each step to be cached increases reusability, decreases disk use, and speeds up docker build. By default, these intermediate layers are not displayed.

An image’s SIZE is the sum of its parents’ sizes. The Tar file used by Docker when it saves images also uses this amount of space.

The image will be listed more than once if it has multiple repository names or tags. The IMAGE ID of this image is used once for one image

# docker images

Run the following command to search a Docker registry for an image.

# Docker search [search term]# docker search ubuntu

If you are searching for an image with Centos OS, you can use any search term like centos. As an example:

In this case,

NAME: It’s the name of the Docker image.

DESCRIPTION: An explanation of what the image is about.

STARS: The number of likes the image has received.

OFFICIAL: Indicates whether an image is based on a trustworthy source.

AUTOMATED: Indicates that the images have been automatically built by pushing them to the Bitbucket or GitHub repositories.

Pulling Docker Image

From the Linux repository at Docker Hub, you can download images for the Docker Engine that are compatible with Linux. You can find a list of Linux images here

To download a Linux image, use the docker pull command, for example:

# docker pull ubuntu:14:04(name:tag)

As you can see,

NAME — A group of images with a similar function, ubuntu is an example.

TAG — A tag that identifies an image, such as ubuntu:14.04.

For Example, to pull ubuntu:14.04 image :

Unless the optional tag field is specified in the above command, the image with the most recent tag will be pulled by default. The images can also be pulled from a specific tag. For Example :

# docker pull –all-tags [name]

Listing Docker Images

Listing downloaded images can be done with the following command.

# docker images

Run Docker Container

Finally, we can execute an interactive command on the running container using its id by using the following command.

# docker run it ubuntu:14.04

Listing Running Containers

You can list running containers with the following command.

# docker ps

Using this command, you will get the following output format. It provides you with important information such as the container id, image, status, etc. In addition, you can use the container ID for further operations such as stopping or removing the container. The following example shows a container running Redis.

Container Life-cycle

A container life cycle can be illustrated by the following figure.

  1. CREATED: We discussed the “docker run” command in greater detail in the last section. There are two granular commands within this command. A docker container will be created from a Docker image when you use the create <image_name> command. The state of the container will be changed to “CREATED” with this command. A container identifier will be returned by this command.

2. STARTED: An image is made up of a file system snapshot and a default startup command, as we discussed in a previous section. You can move a container’s state to “STARTED” after creating it by executing the default startup command. A running version of the default program is available at this point.

3. PAUSED: Using the docker pause container_id command, you can move a container into the paused state. All processes in a container will be suspended.

4. EXITED: By issuing the docker stop container_id command, a container can be moved to the EXITED state. Basically, it will end the primary process within the container. However, the docker start container_id command can be used to put an EXITED container back into a running state.

5. DEAD: Docker rm container_id can be used to move a container to the DEAD state. As a result, the container will be terminated. Dead containers cannot be restarted.

Stopping Containers

This can be done by issuing the below command. As already explained in the section on container life-cycle, a container can be stopped by executing this command.

# docker ps -a

Here is the output for the corresponding input. Observe that two of the containers are in the “Exited” state, and only one is in the “Up” state.

Restarting Stopped Containers

It is possible to relaunch a stopped command by using the following command.

# docker start container_id

In the CREATED state, a container can also be started with the same command.

for interactive mode

An input, output, and error stream for the local standard input and output of the running container

# docker attach container_id

With the exit command you are able to shut down your docker container

Remove Docker Container

Containers need to be stopped (exited) in order to remove them with the above command. If a container is running, you need to run the following command in order to remove it.

# docker rm -f container_id

The use of docker ps -a -q is to see the entire container id whether it is running or stopped

# docker ps -a -q

In order to remove all containers with the above command, containers must be stopped (exited). To remove a running and dead container, run the following command.

# docker rm -f $(docker ps -a -q)

Removing Images

Using the below command, you can clear the cache for an image.

Conclusion

We primarily wanted to introduce you to Docker in this article. It is my hope that you gained a good understanding of the fundamental concepts. I appreciate your help!

--

--

Future Techno India
Future Techno India

Written by Future Techno India

We believe in making future tech leaders by providing right education to them. https://www.payumoney.com/webfronts/#/index/Expertise-on-Container

No responses yet