Docker Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Virtual Machines

A
  • Use the hypervisor to emulate real hardware
  • Can take up a lot of space
  • Require you to install/configure operating system
  • Can run multiple apps simultaneously
  • Cannot interact with their hosts
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Containers

A
  • Do not emulate any hardware
  • Do not need to boot up
  • Do not require operating system installation
  • Take up much less space
  • Can run only one app at a time (by design)
  • Can interact with their hosts
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Namespaces

A
  • Provide different views of your system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

USERNS Namespace

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

MOUNT Namespace

A
  • Access to file systems
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

NET Namespace

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

IPC Namespace

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

TIME Namespace

A
  • Ability to change time (not supported by Docker)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

PID Namespace

A
  • Process ID management
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

CGROUP Namespace

A
  • Create control groups
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

UTC Namespace

A
  • Create/host domain names
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Control Group Uses

A
  • Monitor and restrict CPU usage
  • Monitor and restrict network and disk bandwidth
  • Monitor and restrict memory consumption
  • Assign disk quotas (not supported by Docker)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Docker Limitations

A
  • Natively only runs on Linux
  • Container images are bound to their parent operating systems
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Docker Machine

A
  • Uses VirtualBox to create VMs that only run Docker
  • VirtualBox, VM, and VBoxManage knowledge required
  • Slower than Docker on Linux
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Docker Desktop

A
  • Smaller and more tightly integrated VMs
  • Automatically handles volume and network port mapping
  • Comes with a nice GUI
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Create a Docker Container (Long Way)

A
  • Run “docker container create <NAME>"</NAME>
  • Run “docker ps” to see running containers and “docker ps –all” to see all of them
  • Run “docker logs <ID>" to see the container log messages</ID>
  • Run “docker container start –attach” to link the log to the terminal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Create a Docker Container (Short Way)

A
  • Run “docker run <NAME>" to create a container, start it, and attach its output to the terminal</NAME>
  • Use “docker ps” to get the container ID
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Create a Docker Container from Dockerfiles

A
  • Run “docker built -t <BUILDNAME> to build a container from the Dockerfile</BUILDNAME>
  • Add the “–file <FILENAME> flag if the file is named differently</FILENAME>
  • Docker creates intermediate images after each command and squashes them into a final image at the end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Dockerfile Keywords (FROM)

A
  • FROM: which existing image to base your image from
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Dockerfile Keywords (LABEL)

A
  • LABEL: additional image data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Dockerfile Keywords (USER)

A
  • USER: specifies which user to use for subsequent commands
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Dockerfile Keywords (COPY)

A
  • COPY: copies files from the “context” directory to the container image
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Dockerfile Keywords (RUN)

A
  • RUN: command statements to customize the container image
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Dockerfile Keywords (ENTRYPOINT)

A
  • ENTRYPOINT: specifies what command containers from the image should run
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Interact with your Container

A
  • Run “docker kill <ID>" to forcefully stop a container</ID>
  • Run “docker run -d <NAME>" to start the container without attaching it to the terminal</NAME>
  • Run “docker exec <ID> <CMD>" to run additional commands within a container</CMD></ID>
  • Run “docker exec –interactive –tty <ID> <SHELL>" to start a new terminal session within a container</SHELL></ID>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Stopping and Removing the Container

A
  • By default Docker does not stop and remove a container
  • Run “docker stop <ID>" to stop a container</ID>
  • Run “docker stop -t 0 <ID>" to forcefully stop a container</ID>
  • Run “docker rm <ID>" to remove a container</ID>
  • Run “docker rm -f <ID>" to remove a container that is running</ID>
  • Run “docker ps -aq l xargs docker rm” to remove all containers
  • Run “docker rmi <NAME>" to remove an image</NAME>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Binding Ports to your Container

A
  • Add the “–name <CONTAINER>" flag to the docker run command to name a container</CONTAINER>
  • Add the “-p <LOCAL>:<CONTAINER>" flag to map a port</CONTAINER></LOCAL>
  • “docker run -d –name <CONTAINER> -p <LOCALPORT>:<CONTAINER> <IMAGE>"S</IMAGE></CONTAINER></LOCALPORT></CONTAINER>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Saving Data from Containers

A
  • Add the “–volume <LOCAL>:<CONTAINER> to map the container</CONTAINER></LOCAL>
  • If you map a non-existing file, Docker will create a new directory on your machine
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Pushing Images to Docker Hub

A
  • Run “docker tag <NAME> <USERNAME>/<NAME>:<VERSION> to rename the image</VERSION></NAME></USERNAME></NAME>
  • Run “docker push <USERNAME>/<NAME>:<VERSION> to push to Docker Hub</VERSION></NAME></USERNAME>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

“I can’t create more containers”

A
  • Run “docker images” to list images and “docker rmi <ID>" to remove images</ID>
  • Run “docker system prune” to remove unused data
31
Q

“My container is really slow”

A
  • Run “docker stats <ID>" to see container stats</ID>
  • Run “docker top <ID>" to see what is running inside the container</ID>
  • Run “docker inspect <ID>" to see advanced information in JSON format</ID>
32
Q

Docker Best Practices

A
  • Use verified images
  • Use a container image scanner if necessary
  • Avoid using the “latest” tag
  • Use non-root users
33
Q

Writing a Dockerfile (FROM)

A
  • FROM <IMAGE>: specifies which base image to use</IMAGE>
34
Q

Writing a Dockerfile (WORKDIR)

A
  • WORKDIR <DIR>: sets the working directory</DIR>
35
Q

Writing a Dockerfile (COPY)

A
  • COPY <CWD> <DIR>: copies current directory contents into the container</DIR></CWD>
36
Q

Writing a Dockerfile (RUN)

A
  • RUN pip install –no-cache-dir -r requirements.txt
37
Q

Writing a Dockerfile (ENV)

A
  • FLASK_APP=app.py: sets env variable for Flask
38
Q

Writing a Dockerfile (CMD)

A
  • CMD [“flask”, “run”, “–host=0.0.0.0”]: starts the Flask application
39
Q

Searching for Images in the Docker Hub

A

Run “docker search <IMAGE>"</IMAGE>

40
Q

Other Docker Hub Image Search Flags

A
  • ”–limit x”: limits to x results
  • ”–no-trunc”: returns full image descriptions
  • ”–format”: formats results using Go template
41
Q

Docker Hub Image Search Filters

A
  • ”–filter is_official=true”: filters by official images
  • ”–filter stars=x”: filters by minimum stars
  • ”–filter is_automated=true”: filters by images that can be built automatically
42
Q

Working with Custom Images

A
  • Run “docker images ls” to see local images
  • ”–all” flag to see intermediate images
  • ”–quiet” flag to only return image IDs
  • ”–filter before=<IMAGE>" to filter images before <IMAGE></IMAGE></IMAGE>
  • ”–filter after=<IMAGE>" to filter images after <IMAGE></IMAGE></IMAGE>
  • ”–filter dangling=true” to filter unused images
  • ”–filter label=<label>” to filter by image label</label>
43
Q

Tagging and Labeling Images

A
  • Tags specify the version of an image
  • Run “docker build -t <NAME>:<TAG>" to add a tag</TAG></NAME>
  • Run “docker tag <source></source>:<TAG> <TARGET>:<TAG>" to add a tag</TAG></TARGET></TAG>
44
Q

Working with a Private Image Repository

A
  • Run “docker login”
  • Tag the local repository using the name of the repository: “docker tag <NAME>:<VERSION> <USERNAME>/<REPO>:<NAME>"</NAME></REPO></USERNAME></VERSION></NAME>
  • Run “docker push <USERNAME>/<REPO>:<IMAGE></IMAGE></REPO></USERNAME>
45
Q

Inspecting Images

A
  • Run “docker image inspect <ID>"</ID>
  • Run “docker image inspect –format=’{{json.Config.Labels}}’ <IMAGE>" to return a specific section in json format</IMAGE>
46
Q

Inspecting Images (RepoTags)

A
  • List all tags associated with the image ID
47
Q

Inspecting Images (ContainerConfig)

A
  • Container information
48
Q

Inspecting Images (Config)

A
  • Environment settings
49
Q

Inspecting Images (Cmd)

A
  • Command run when starting a container based on the image (configured in Dockerfile)
50
Q

Inspecting Images (Labels)

A
  • Image labels
51
Q

Removing Images

A
  • Run “docker rmi <NAME> to remove an image"</NAME>
  • Add the “-f” flag to remove an image attached to a running container
  • Run “docker rmi <ID>" to remove all tags from an image</ID>
52
Q

Start an Existing Container

A
  • Run “docker start”
53
Q

Create and Start a Container

A
  • Run “docker run”
54
Q

Gracefully Stop a Container

A
  • Run “docker stop”
55
Q

Forcefully Stop a Container

A
  • Run “docker kill”
56
Q

List all Running Containers

A
  • Run “docker ps”
  • The “-a” flag includes stopped containers
  • The “-n” flag returns the last x created containers
  • The “-q” flag displays only container IDs
  • The “-s” flag displays the total file size of all containers
  • The “-l” flag shows the last created container
57
Q

Inspecting Containers

A
  • Run “docker inspect <ID>"</ID>
  • Can return a specific section in json format similar to inspect image
58
Q

Inspecting Containers (ID)

A
  • Container ID
59
Q

Inspecting Containers (State)

A
  • Status flags and PID
60
Q

Inspecting Containers (Image)

A
  • The image that the container is running
61
Q

Inspecting Containers (LogPath)

A
  • Path to the container log
62
Q

Inspecting Containers (Name)

A
  • Name of the container
63
Q

Inspecting Containers (RestartCount)

A
  • The number of times a container has restarted
64
Q

Inspecting Containers (HostConfig)

A
  • How the container will interact with the host system
65
Q

Inspecting Containers (Config)

A
  • Runtime configuration options
66
Q

Reviewing Container Log Files

A
  • Run “docker logs <ID>" to view container logs</ID>
  • The “tail” option specifies last x lines to show
  • The “f” option continues streaming new output
  • The “details” option shows extra log details
  • The “since” option shows logs after a specified time
  • The “until” option shows logs until a timestamp
  • The “timestamps” option shows timestamps in logs
67
Q

Working with Volumes

A
  • A volume is a directory on the host machine that is accessible by a container
68
Q

Create a Volume

A
  • Run “docker volume create”
69
Q

View Existing Volumes

A
  • Run “docker volume ls”
70
Q

Inspect a Volume

A
  • Run “docker volume inspect <NAME>"</NAME>
71
Q

Attach a Volume to a Container

A
  • Add “-v <HOST>:<CONTAINER>"</CONTAINER></HOST>
72
Q

Remove an Unused Volume

A
  • Run “volume rm <NAME>"</NAME>
73
Q

Working with Mounts

A
  • Use “-v” or “–mount” to bind a host directory to a container directory
  • “-v” will create a new directory if it doesn’t exist on the host, while “–mount” will return an error
  • Run “docker exec -it <ID> sh" to open a shell in the container and verify the mount binding worked</ID>
74
Q

Daily Docker Workflow

A
  • Run “docker image prune” to remove untagged and unreferenced images
  • Add “-a” flag to remove all unused images
  • Run “docker container prune” and “docker volumes prune” in similar ways
  • Run “docker system prune” to remove unused images, containers, and networks
  • Add “–volume” flag to prune volumes