0% found this document useful (0 votes)
16 views4 pages

Commands

The document provides a comprehensive guide on various Docker commands, including how to list container statuses, export and import images, check versions, and manage containers. It covers commands for logging into Docker repositories, creating and modifying containers, as well as deleting and pushing images. Additionally, it explains how to obtain information about running, paused, and stopped containers using specific commands.

Uploaded by

Bhumi Ahlawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Commands

The document provides a comprehensive guide on various Docker commands, including how to list container statuses, export and import images, check versions, and manage containers. It covers commands for logging into Docker repositories, creating and modifying containers, as well as deleting and pushing images. Additionally, it explains how to obtain information about running, paused, and stopped containers using specific commands.

Uploaded by

Bhumi Ahlawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

What is the docker command that lists the status of all docker
containers?
-In order to get the status of all the containers, we run the below command: docker ps –a

2. What command can you run to export a docker image as an archive?


-This can be done using the docker save command and the syntax is: docker save -o
<exported_name>.tar <container-name>

3. What command can be run to import a pre-exported Docker image into


another Docker host?
-This can be done using the docker load command and the syntax is: docker load -i
<export_image_name>.tar

4. What command is used to check for the version of docker client and
server?
-The command used to get all version information of the client and server is the docker version.
To get only the server version details, we can run docker version --format '{{.Server.Version}}'

5. How to check for Docker Client and Docker Server version?


-The following command gives you information about Docker Client and Server versions:
$ docker version

6. How do you get the number of containers running, paused and stopped?
-You can use the following command to get detailed information about the docker installed on your
system.
$ docker info
You can get the number of containers running, paused, stopped, the number of images and a lot more.

7. If you vaguely remember the command and you’d like to confirm it, how
will you get help on that particular command?
-The following command is very useful as it gives you help on how to use a command, the syntax, etc.
$ docker --help
The above command lists all Docker commands. If you need help with one specific command, you can use
the following syntax:
$ docker <command> --help

8. How to login into docker repository?


-You can use the following command to login into hub.docker.com:
$ docker login
You’ll be prompted for your username and password, insert those and congratulations, you’re logged in.

9.If you wish to use a base image and make modifications or personalize it,
how do you do that?
-You pull an image from docker hub onto your local system
It’s one simple command to pull an image from docker hub:
$ docker pull <image_name>

10. How do you create a docker container from an image?


-Pull an image from docker repository with the above command and run it to create a container. Use the
following command:
$ docker run -it -d <image_name>
Most probably the next question would be, what does the ‘-d’ flag mean in the command?
-d means the container needs to start in the detached mode. Explain a little about the detach mode. Have
a look at this blog to get a better understanding of different docker commands.

11. How do you list all the running containers?


-The following command lists down all the running containers:
$ docker ps

12. Suppose you have 3 containers running and out of these, you wish to
access one of them. How do you access a running container?
-The following command lets us access a running container:
$ docker exec -it <container id> bash
The exec command lets you get inside a container and work with it.

13. How to start, stop and kill a container?


-The following command is used to start a docker container:
$ docker start <container_id>
and the following for stopping a running container:
$ docker stop <container_id>
kill a container with the following command:
$ docker kill <container_id>

14 . Can you use a container, edit it, and update it? Also, how do you make it a
new and store it on the local system?
-Of course, you can use a container, edit it and update it. This sounds complicated but its actually just one
command.
$ docker commit <conatainer id> <username/imagename>

15. Once you’ve worked with an image, how do you push it to docker hub?
-$ docker push <username/image name>

16. How to delete a stopped container?


-Use the following command to delete a stopped container:
$ docker rm <container id>

17. How to delete an image from the local storage system?


The following command lets you delete an image from the local system:
$ docker rmi <image-id>

18. How to build a Dockerfile?


Once you’ve written a Dockerfile, you need to build it to create an image with those specifications. Use the
following command to build a Dockerfile:
$ docker build <path to docker file>
The next question would be when do you use “.dockerfile_name” and when to use the entire path?
Use “.dockerfile_name” when the dockerfile exits in the same file directory and you use the entire path if it
lives somewhere else.

19. Do you know why docker system prune is used? What does it do?
$ docker system prune
The above command is used to remove all the stopped containers, all the networks that are not used, all
dangling images and all build caches. It’s one of the most useful docker commands.

20. What Command Can You Run to Export a Docker Image As an Archive?
You can use this following command to export a Docker image as an archive:
docker save -o <output_file_name>.tar <image_name>

21. What Command Can Be Run to Import a Pre-Exported Docker Image Into
Another Docker Host?
We can use this following command to import a pre-exported Docker image into another host:
docker load -i <input_file_name>.tar

22. Can a Paused Container Be Removed From Docker?


Yes, a paused container can be removed using the command with rm option:
docker rm <container_id>
23. How Do You get the Number Of Containers Running, Paused, and
Stopped?
For obtaining the number of running, paused, and stopped containers in Docker you can use the command
such as `docker ps -q` for knowing the list of running containers and `docker ps -q -f "status=paused"` for
paused ones. Stopped containers can be counted using `docker ps -aq -f "status=exited"`. These commands
will the provide the list of container IDs , and you have to can further process the output to get the counts
programmatically like `docker ps -q | wc -l`.
The following command is used to know number of container are in running state:
docker ps -q | wc -l
The following command is used to know number of container are in paused state:
docker ps -aq -f "status=paused" | wc -l
The following command is used to know number of containers are in stopped state:
docker ps -aq -f "status=exited" | wc -l

You might also like