Docker-Compose Flashcards

1
Q

What is the difference between Docker and Docker-Compose?

A

+ Docker is the Enginee where Containers run.
+ Docker-Compose is a irchestrator where you can define services with multiple images.

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

What is the first line that a YAML archive, of docker-compose must start?

A

VERSION <version_id>

The VERSION of Docker Compose that is working with.

(*) You should valid the compatibility of the version against Docker Enginee

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

What is the difference between these commands?

  1. $docker-compose --version
  2. $docker compose version
A

Nothing, both of them are valid but you only are able to use docker compose since the upgrade to Docker Compose V2.x.

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

What is a Compode YAML File?

A

The Compose file is a YAML file defining version (DEPRECATED), services (REQUIRED), networks, volumes, configs and secrets.

https://docs.docker.com/compose/compose-file/

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

What is the defaul path of Compose File?

A

compose.yaml or compose.yml

https://docs.docker.com/compose/compose-file/

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

In a Compose File, Is this path, in VOLUMES, valid for a windows as a linux enviroment?

yaml
volumes:
  - ./mypath:myfile_datbase.d
A

YES.

Docker File need this notation and it’s able to translate the path to use the separator that OS needs (\ or /).

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

How can you define Services in a docker compose file?

A

Declaring them after the VERSION into the STATEMEN services: which is at the same level than VERSION:

```YAML
version: ‘3.1’

services:
#My Service
my_service:
~~~

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

How can you tell to docker compose how to download an image and install it:

A

From a secction of a service, you must define the name of the image to downlad and install it, using the property image:<image_name>:<tag>:

```YAML
services:
#database engine service
postgres_db:
container_name: postgres
image: postgres:latest
~~~

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

How can you tell to docker compose building a new image from a Dockerfile?

A

Defining into the service propertyes the service’s statement build:

YAML
billingapp-back:
    build:
      context: ./java
      args:
        - JAR_FILE=*.jar
 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In this YAMLE segment, what is the function of context:

YAML
billingapp-back:
    build:
      context: ./java
      args:
        - JAR_FILE=*.jar
 
A

Define the conextx where de Dockerfile is in reference of the path where the docker-compose is executed.

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

In this code
1. What is the function of volumes?
2. How does it work?

```YAML
services:
postgres_db:
container_name: postgres
image: postgres:latest
restart: always
ports:
- 5432:5432
volumes:
data directory is empty
- ./dbfiles:/docker-entrypoint-initdb.d
- /var/lib/postgres_data:/var/lib/postgresql/data
~~~

A
  1. Declare section where you can map local diretory to a container’s directory. It’s useful to set a persistent repository of files even thoug the container is deleted.
  2. The first path is local directory which will be accessed through the container’s directory.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In this services declaration, what is the function of enviroment? and how does it works?

```YAML
billingapp-back:
build:
context: ./java
args:
- JAR_FILE=*.jar
container_name: billingApp-back
environment:
- JAVA_OPTS=
-Xms256M
-Xmx256M
~~~

A

It will declare Enviroment Variables that will be used in a Dokerfile. in this case the JAVA_OPTS is used in Dockerfile as:

```YAML
FROM openjdk:8-jdk-alpine
RUN addgroup -S devopsc && adduser -S javams -G devopsc
USER javams:devopsc
ENV JAVA_OPTS=””
~~~

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

In this service declaration, what is the function of depends_onproperty?

```YAML
billingapp-back:
build:
context: ./java
args:
- JAR_FILE=*.jar
container_name: billingApp-back
depends_on:
- postgres_db
ports:
- 8080:8080
~~~

A
  • That depends of all those services declared into depends_on to run.
  • This service will run once the depends are running.

```YAML
services:
#database engine service
postgres_db:
container_name: postgres

#database admin service
adminer:

depends_on:
- postgres_db
ports:
- 9090:8080
~~~

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

What is the command to “compile” and build service from a docker-compose YAML file?

A

docker-compose -f <file.yaml> build

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

How to initialize (run) all the services defined ina Docker Compose File (YAML) and deatach from console?

A

docker-compose -f <file.yaml> up -d

-d is for deatach the proccess from console.

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

How to stop all the services defined ina Docker Compose File (YAML) that are already running?

A

docker-compose -f <file.yaml> stop

17
Q

What is the basic command to know the resources that each container is using?

A

docker stats

18
Q

What is the command to deploy a YAML File and recreate its containers?

A

docker-compose -f <YAML File> up -d --force-recreate

--force-recreate to recreate the containers

- d to deatache from the console

19
Q

Wha is the correct way to set limit of resource of memory into a serivice configuration?

A
deploy:
   resources:
     limits:
       cpus: "0.15"
       memory: 250M
20
Q

Wha is the correct way to set the inital resources that a service must use on running?

A
    deploy:
        reservations:
          cpus: "0.1"
          memory: 128M
21
Q

What is the mistake in this declaration of resource limits?

    deploy:
      resources:
        limits:
          cpus: "0.15"
          memory: 250M
        reservations:
          cpus: 0.1
          memory: 128M
A

That the cpus MUST be delcared with cuotes ("0.1").