Docker Flashcards
What is a Docker Image?
A Docker Image is a file which contains all the necessary dependency and configurations which are required to run an application.
What is a Docker Container?
A Docker Container is essentially a running instance of an image.
Are Docker containers created with a UUID?
Yes, when the container is created a UUID is created. The UUID can be used to help identify the container.
What happens when you do not specify a name for a container?
Docker will supply a randomly generated name from two words joined together by an underscore
How do you add a name to a Docker container?
You can add –name to your command
What does the number to the left a port mapping signify?
The port that the host machine is listening on
What does the number to the right a port mapping signify?
The port that the container is listening on
What is the benefit of running a container in the foreground mode?
You will be able to all of the output from the container
Is foreground or detached mode default for a container?
Foreground is default for a container
What command lists all running containers?
docker ps
What command lists all containers running or otherwise?
docker ps -a
How do you stop a container by name?
docker container stop <image_name></image_name>
How do you list all containers within the environment?
docker container ls -aq
How would you stop all containers with one command?
docker container stop $(docker container ls -aq)
How would you remove a container?
docker container rm <image_name></image_name>
How would you remove all containers with one command?
docker container rm $(docker container ls -aq)
How do you interactively run a command on a running container?
docker container exec -it <image_name> <command></command></image_name>
Can you run the docker container exec command if the primary process is running?
No
What does the command docker container start docker-exec do?
Starts the primary process for an exited container
What does the -i flag stand for as in:
docker container exec -i
Interactive flag that keeps stdin open
What does the -t flag stand for as in:
docker container exec -t
Allocates a pseudo-TTY
How do you override the default container command?
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
Do Docker containers restart when they exit or when the docker daemon is restarted?
No
How do you specify a restart policy
Add the –restart flag with the docker run command