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?

A

No

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?

A

No

24
Q

How do you specify a restart policy

A

Add the –restart flag with the docker run command

25
Q

How do you restart the container if it exits due to an error, which manifests as a non-zero exit code?

A

Add the –restart on-failure with the docker run command

26
Q

How do you restart the container unless it is explicitly stopped or Docker itself is stopped or restarted?

A

Add the –restart unless-stopped with the docker run command

27
Q

How do you always restart the container if it stops?

A

Add the –restart always with the docker run command

28
Q

What is the default restart policy?

A

–restart no

29
Q

How do you remove a stopped container?

A

docker rm <container_name></container_name>

30
Q

How do you remove a running container?

A

docker rm -f <container_name></container_name>

31
Q

How do you see overall disk metrics related to all images, containers, local volumes, and build cache?

A

docker system df

32
Q

How do you see the container that is using the greatest amount of disk space?

A

docker system df -v

33
Q

How do you see image space usage?

A

docker system df -v

34
Q

How do you see containers space usage?

A

docker system df -v

35
Q

How do you see local volumes space usage?

A

docker system df -v

36
Q

How do you see build cache usage?

A

docker system df -v