Docker 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
Interact with your Container
- Run "docker kill " to forcefully stop a container - Run "docker run -d " to start the container without attaching it to the terminal - Run "docker exec " to run additional commands within a container - Run "docker exec --interactive --tty " to start a new terminal session within a container
26
Stopping and Removing the Container
- By default Docker does not stop and remove a container - Run "docker stop " to stop a container - Run "docker stop -t 0 " to forcefully stop a container - Run "docker rm " to remove a container - Run "docker rm -f " to remove a container that is running - Run "docker ps -aq l xargs docker rm" to remove all containers - Run "docker rmi " to remove an image
27
Binding Ports to your Container
- Add the "--name " flag to the docker run command to name a container - Add the "-p :" flag to map a port - "docker run -d --name -p : "S
28
Saving Data from Containers
- Add the "--volume : to map the container - If you map a non-existing file, Docker will create a new directory on your machine
29
Pushing Images to Docker Hub
- Run "docker tag /: to rename the image - Run "docker push /: to push to Docker Hub
30
"I can't create more containers"
- Run "docker images" to list images and "docker rmi " to remove images - Run "docker system prune" to remove unused data
31
"My container is really slow"
- Run "docker stats " to see container stats - Run "docker top " to see what is running inside the container - Run "docker inspect " to see advanced information in JSON format
32
Docker Best Practices
- Use verified images - Use a container image scanner if necessary - Avoid using the "latest" tag - Use non-root users
33
Writing a Dockerfile (FROM)
- FROM : specifies which base image to use
34
Writing a Dockerfile (WORKDIR)
- WORKDIR : sets the working directory
35
Writing a Dockerfile (COPY)
- COPY : copies current directory contents into the container
36
Writing a Dockerfile (RUN)
- RUN pip install --no-cache-dir -r requirements.txt
37
Writing a Dockerfile (ENV)
- FLASK_APP=app.py: sets env variable for Flask
38
Writing a Dockerfile (CMD)
- CMD ["flask", "run", "--host=0.0.0.0"]: starts the Flask application
39
Searching for Images in the Docker Hub
Run "docker search "
40
Other Docker Hub Image Search Flags
- "--limit x": limits to x results - "--no-trunc": returns full image descriptions - "--format": formats results using Go template
41
Docker Hub Image Search Filters
- "--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
Working with Custom Images
- Run "docker images ls" to see local images - "--all" flag to see intermediate images - "--quiet" flag to only return image IDs - "--filter before=" to filter images before - "--filter after=" to filter images after - "--filter dangling=true" to filter unused images - "--filter label=
43
Tagging and Labeling Images
- Tags specify the version of an image - Run "docker build -t :" to add a tag - Run "docker tag : :" to add a tag
44
Working with a Private Image Repository
- Run "docker login" - Tag the local repository using the name of the repository: "docker tag : /:" - Run "docker push /:
45
Inspecting Images
- Run "docker image inspect " - Run "docker image inspect --format='{{json.Config.Labels}}' " to return a specific section in json format
46
Inspecting Images (RepoTags)
- List all tags associated with the image ID
47
Inspecting Images (ContainerConfig)
- Container information
48
Inspecting Images (Config)
- Environment settings
49
Inspecting Images (Cmd)
- Command run when starting a container based on the image (configured in Dockerfile)
50
Inspecting Images (Labels)
- Image labels
51
Removing Images
- Run "docker rmi to remove an image" - Add the "-f" flag to remove an image attached to a running container - Run "docker rmi " to remove all tags from an image
52
Start an Existing Container
- Run "docker start"
53
Create and Start a Container
- Run "docker run"
54
Gracefully Stop a Container
- Run "docker stop"
55
Forcefully Stop a Container
- Run "docker kill"
56
List all Running Containers
- 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
Inspecting Containers
- Run "docker inspect " - Can return a specific section in json format similar to inspect image
58
Inspecting Containers (ID)
- Container ID
59
Inspecting Containers (State)
- Status flags and PID
60
Inspecting Containers (Image)
- The image that the container is running
61
Inspecting Containers (LogPath)
- Path to the container log
62
Inspecting Containers (Name)
- Name of the container
63
Inspecting Containers (RestartCount)
- The number of times a container has restarted
64
Inspecting Containers (HostConfig)
- How the container will interact with the host system
65
Inspecting Containers (Config)
- Runtime configuration options
66
Reviewing Container Log Files
- Run "docker logs " to view container logs - 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
Working with Volumes
- A volume is a directory on the host machine that is accessible by a container
68
Create a Volume
- Run "docker volume create"
69
View Existing Volumes
- Run "docker volume ls"
70
Inspect a Volume
- Run "docker volume inspect "
71
Attach a Volume to a Container
- Add "-v :"
72
Remove an Unused Volume
- Run "volume rm "
73
Working with Mounts
- 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 sh" to open a shell in the container and verify the mount binding worked
74
Daily Docker Workflow
- 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