Docker Flashcards

1
Q

What is Docker?

A

Docker is a tool for creating, deploying, and running applications easily

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

Why use Docker?

A

Docker allows to packge applications with all their dependencies and distribute them as individual bundles with that Docker guarantees that the applications will run the same way on every Docker instance

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

What is a Docker image?

A

A docker image is a file that represents a packaged application with all the dependencies needed to run correctly -> An image is like a java class

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

How are docker images built?

A

Docker images are built as series of layers and these layers are assembled on top of one another and simply put, a layer is an image

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

What do we need for a Docker image of a Hello World application?

A
  1. Operating System Layer
  2. JVM
  3. Hello World application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a docker container?

A

A docker container is an instance of an image and can be identified by its ID -> A docker container is like an instance of a java class

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

What are the states for a container that docker defines?

A

Created, restarting, running, removing, paused, exited, and dead

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

What are the advantages of containers?

A
  • Containers are lightweight VMs
  • Their behaviors are completely isolated from each other
  • Easy way of scaling applications because we can run multiple containers of the same image at the same time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is usually the first layer of a docker image?

A

The first layer of a docker image is usually the operating system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can we pass environment variables to docker containers?

A
  • Using -env, -e
  • Using -env-file
  • Using docker compose
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What ways of interactive exploring are there to check configurations or log files inside a container?

A
  • Running a container with shell access using the docker run command with the -it option
  • Spawning a shell in a running container with docker exec
  • Non-interactive exploring
  • Copying the filesystem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What ways are there to copy files to and from a docker container?

A
  • Using the docker cp command
  • Volume mounts
  • Dockerfile with COPY
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When can we use the docker cp command?

A

Docker cp cannot be used to copy between two containers. It can only be used to copy files between the host system and a single container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a bind mount?

A

A docker bind mount is a high-performance connection from the container to a directory on the host machine -> It allows the host to share its own file system with the container, which can be made read-only or read-write

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a volume mount?

A

A volume is a directory on the host machine that is accessible to a container, so that the data is not stored in the container’s filesystem but instead it is stored in the host machine filesystem. The data persists even if the container is deleted or recreated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are use cases for bind mounts?

A
  • Developing and testing applications locally
  • Sharing code or configuration files between host and container
  • Debugging applications by accessing log files
17
Q

What are use cases for volume mounts?

A
  • Storing application data that needs to persist
  • Sharing data between different containers
  • Backing up data
18
Q

When and why is it a good idea to use docker compose?

A

When using docker, the management of several different containers quickly becomes cumbersome, docker compose is a tool that helps to overcome this problem and easily handle multiple containers at once

19
Q

What is important about the YAML configuration file?

A

Docker compose works by applying many rules declared within a single docker-compose.yml configuration file

20
Q

What are services?

A

Services refer to the containers’ configuration. Components that can be split in different images are defined as individual services

21
Q

What are networks in docker?

A

Networks define the communication rules between containers, and between a container and the host

22
Q

What types of volumes exist?

A

There are three types of volumes: anonymous, named, and host

23
Q

What is the priority order that compose uses?

A
  1. Compose file
  2. Shell environment variables
  3. Environment file
  4. Dockerfile
  5. Variable not defined
24
Q

What are the benefits of docker compose?

A

Docker compose is a powerful tool for defining and running multi-container docker applications. It allows developers to define their application’s services, networks, and volumes in a single YAML file, making it easy to deploy and manage complex applications. Container management is easier with docker’s service profiles, which allow users to define containers’ configurations specifically

25
Q

What are docker compose services?

A

A docker service is a logical grouping of containers that work together to provide a specific function. In docker compose, a service refers to a containerized application element that can be horizontally scaled. It allows multiple instances of the same service to run simultaneously

26
Q

What are service profiles?

A

Docker compose files define specific configurations for containers that run in a docker service based on service profiles -> These service profiles allow us to define configurations for specific containers that run as part of a service. As a result, they simplify container management and also maintain the correct configurations

27
Q

What is the main difference between COPY and ADD?

A

The ADD directive is more powerful in two ways: 1. It can handle remote URLs for its source argument (the COPY directive can only accept local files) and 2. the ADD directive can auto-extract tar files into the image file system

28
Q

When to use ADD or COPY?

A

We should always prefer COPY over ADD unless we specifically need one of the two additional features of ADD because using ADD to copy remote files into a docker image creates an extra layer and increases the file size

29
Q

When does the run command execute?

A

The run instruction executes when we build the image

30
Q

When does the cmd command execute?

A

The cmd instruction specifies a default command that executes everytime when the container starts

31
Q

When does the entrypoint command execute?

A

The entrypoint behaves similarly to cmd but in addition it allows us to customize the command executed at startup

32
Q

What are tips for creating efficient docker images?

A
  • Base your image on an official one -> Avoid building new images when possible
  • Create slimmed down images
  • Use slim versions when available
  • Use multi-stage builds
33
Q

What is the multi-stage build feature in docker?

A

The multi-stage build feature in docker allows developers to create a sequence of builds, each with its own set of instructions -> This helps in optimizing the size of the resulting image and one of the challenges in multi-stage builds is copying variables between stages, which allows us to reuse values in subsequent stages of the build process

34
Q

What ways are there to copy variables between stages in a multi-stage docker build?

A
  • Using ARG
  • Using ENV
  • Using File
35
Q

What is the easiest way to copy variables between stages in a multi-stage docker build?

A

Using ARG

36
Q

When is it useful to use ARG in the docker build process?

A

ARG is useful when we need to pass a variable’s value from one stage to another during the build process and when we want to make the value of the variable available during the build process, but not in the final image

37
Q

When is it useful to use ENV in the docker build process?

A

ENV is used to set variables that are available during the build process and also persist in the resulting image

38
Q

When is it useful to use a file in the docker build process?

A

Using a file is useful when we need to make the variable available in the final image: We can write the variable’s value to a file in one stage and then copy it to another stage. Furthermore this approach is useful when we want to copy too many variables across different stages because adding all the variables to a file and sharing it across all the stages is easier