Docker Compose Flashcards

1
Q

Docker Compose Basics

A
  • Markdown tool to specify Docker configurations as code
  • Procedural
  • Declarative
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Production System Considerations

A
  • Multiple Systems
  • Microservices
  • Third-party dependencies
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Procedural

A
  • Series of ordered steps
  • Based on assumptions about the previous step
  • Easy to introduce errors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Declarative

A
  • Specify end results
  • System will determine which steps to execute
  • Produces the same result each time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Main Benefits of Docker Compose

A
  • Version control
  • Self-documenting
  • Easy management
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Designed For

A
  • Local development
  • Staging server
  • Continuous integration testing environment
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Not Designed For

A
  • Distributed systems
  • Complex production environments
  • No autoscaling
  • Use orchestration tools like Docker Swarm or Kubernetes in production
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Docker Compose Configuration

A
  • Create a file “docker-compose.yaml”
  • Version: specifies which version of Docker Compose to use
  • Services: specifies which containers are required (specify a path to the corresponding Docker build file or image)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Start all services defined in the Docker Compose file

A
  • “docker-compose up”
  • Pass in a service name to any command to only apply it to that service
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Stop all containers

A
  • “docker-compose down”
  • Deletes all containers and images and removes all artifacts
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Save battery or free memory

A
  • “docker-compose stop”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Stop and restart all containers

A
  • “docker-compose restart”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Environment Variables

A
  • Accessible inside a running Docker container
  • Specify runtime environment
  • Use env files if necessary (pass in env file path)
  • Including an env variable name without a value will pass in the value from the host server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Build Arguments

A
  • Accessible only at build times
  • Build tool versions
  • Cloud platform configuration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Target Volume

A
  • File directory path inside a container where the volume data lives
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Source Volume

A
  • File directory path on the host machine outside a container where the volume data lives
17
Q

Volume Access Modes

A
  • rw: read-write by default
  • ro: read-only
18
Q

Mounting Volume Syntax

A
  • <source></source>:<TARGET>:<MODE></MODE></TARGET>
19
Q

Named Volumes

A
  • Running “docker-compose up” or “docker-compose restart” will automatically copy old volume data to the new container
  • Running “docker-compose down –volumes” will automatically delete named volumes
  • Without named volumes you can run out of memory
20
Q

Exposing Ports

A
  • Map the ports for all containers in the Docker Compose file
21
Q

Enforcing Container Start-Up Order

A
  • Add a “depends_on” object under a service definition in the Docker Compose file
  • Only guarantees that dependent containers have been started, not that they are healthy and running
22
Q

Advantages of a Single Compose File

A
  • Shared containers
  • Easier integration testing
  • Conceptually one system
23
Q

Named Subsets of Services

A
  • List one or more profile names under the profile keyword for a service
  • A container with no profiles specified is included by default
  • Docker Compose commands will only apply to a service if its profile is explicitly enabled
  • Add “–profile <NAME>" to enable a non-default profile</NAME>
24
Q

Multiple Compose Files

A
  • Distinct desired behaviors that do not coincide
  • Different environments
  • By default, Docker Compose will read docker-compose.yaml and docker-compose.override.yaml
  • Docker Compose will merge the two files
25
Merge Rules for Compose Files
- Array fields: original + override - Single-value fields: preference to override - Override can be a partial or incomplete configuration
26
Run Docker Compose Override
- "docker-compose -f -f "
27
Example Environment Variables
- Image tags - Software versions - Ports
28
Accessing Environment Variables
- Use the syntax "${NAME}"
29
Environment Variable Defaults
- Empty string (automatic) - Inline in docker-compose configuration - In .env file - Throw error if missing (no default) - The host env variable in the shell will always supersede the default
30
Pass in a .env file
- "--env-file "