Docker Flashcards

1
Q

What is a Docker Image?

A

A Docker Image is a file which contains all the necessary dependency and configurations which are required to run an application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a Docker Container?

A

A Docker Container is essentially a running instance of an image.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Are Docker containers created with a UUID?

A

Yes, when the container is created a UUID is created. The UUID can be used to help identify the container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when you do not specify a name for a container?

A

Docker will supply a randomly generated name from two words joined together by an underscore

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you add a name to a Docker container?

A

You can add –name to your command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the number to the left a port mapping signify?

A

The port that the host machine is listening on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the number to the right a port mapping signify?

A

The port that the container is listening on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the benefit of running a container in the foreground mode?

A

You will be able to all of the output from the container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is foreground or detached mode default for a container?

A

Foreground is default for a container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What command lists all running containers?

A

docker ps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What command lists all containers running or otherwise?

A

docker ps -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you stop a container by name?

A

docker container stop <image_name></image_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you list all containers within the environment?

A

docker container ls -aq

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you stop all containers with one command?

A

docker container stop $(docker container ls -aq)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How would you remove a container?

A

docker container rm <image_name></image_name>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How would you remove all containers with one command?

A

docker container rm $(docker container ls -aq)

17
Q

How do you interactively run a command on a running container?

A

docker container exec -it <image_name> <command></command></image_name>

18
Q

Can you run the docker container exec command if the primary process is running?

19
Q

What does the command docker container start docker-exec do?

A

Starts the primary process for an exited container

20
Q

What does the -i flag stand for as in:
docker container exec -i

A

Interactive flag that keeps stdin open

21
Q

What does the -t flag stand for as in:
docker container exec -t

A

Allocates a pseudo-TTY

22
Q

How do you override the default container command?

A

Add the command you want to run after docker container run -d <image> <command></command></image>

After the pid 1 process completes, the container will exit

23
Q

Do Docker containers restart when they exit or when the docker daemon is restarted?

24
Q

How do you specify a restart policy

A

Add the –restart flag with the docker run command

25
How do you restart the container if it exits due to an error, which manifests as a non-zero exit code?
Add the --restart on-failure with the docker run command
26
How do you restart the container unless it is explicitly stopped or Docker itself is stopped or restarted?
Add the --restart unless-stopped with the docker run command
27
How do you always restart the container if it stops?
Add the --restart always with the docker run command
28
What is the default restart policy?
--restart no
29
How do you remove a stopped container?
docker rm
30
How do you remove a running container?
docker rm -f
31
How do you see overall disk metrics related to all images, containers, local volumes, and build cache?
docker system df
32
How do you see the container that is using the greatest amount of disk space?
docker system df -v
33
How do you see image space usage?
docker system df -v
34
How do you see containers space usage?
docker system df -v
35
How do you see local volumes space usage?
docker system df -v
36
How do you see build cache usage?
docker system df -v