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
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
3
Q
Namespaces
A
- Provide different views of your system
4
Q
USERNS Namespace
A
- User lists
5
Q
MOUNT Namespace
A
- Access to file systems
6
Q
NET Namespace
A
- Network communication
7
Q
IPC Namespace
A
- Interprocess communication
8
Q
TIME Namespace
A
- Ability to change time (not supported by Docker)
9
Q
PID Namespace
A
- Process ID management
10
Q
CGROUP Namespace
A
- Create control groups
11
Q
UTC Namespace
A
- Create/host domain names
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)
13
Q
Docker Limitations
A
- Natively only runs on Linux
- Container images are bound to their parent operating systems
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
15
Q
Docker Desktop
A
- Smaller and more tightly integrated VMs
- Automatically handles volume and network port mapping
- Comes with a nice GUI
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
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
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
19
Q
Dockerfile Keywords (FROM)
A
- FROM: which existing image to base your image from
20
Q
Dockerfile Keywords (LABEL)
A
- LABEL: additional image data
21
Q
Dockerfile Keywords (USER)
A
- USER: specifies which user to use for subsequent commands
22
Q
Dockerfile Keywords (COPY)
A
- COPY: copies files from the “context” directory to the container image
23
Q
Dockerfile Keywords (RUN)
A
- RUN: command statements to customize the container image
24
Q
Dockerfile Keywords (ENTRYPOINT)
A
- ENTRYPOINT: specifies what command containers from the image should run
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>
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>
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>
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
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>