Docker-Compose Flashcards
What is the difference between Docker and Docker-Compose?
+ Docker is the Enginee where Containers run.
+ Docker-Compose is a irchestrator where you can define services with multiple images.
What is the first line that a YAML archive, of docker-compose must start?
VERSION <version_id>
The VERSION of Docker Compose that is working with.
(*) You should valid the compatibility of the version against Docker Enginee
What is the difference between these commands?
$docker-compose --version
$docker compose version
Nothing, both of them are valid but you only are able to use docker compose
since the upgrade to Docker Compose V2.x.
What is a Compode YAML File?
The Compose file is a YAML file defining version (DEPRECATED), services (REQUIRED), networks, volumes, configs and secrets.
https://docs.docker.com/compose/compose-file/
What is the defaul path of Compose File?
compose.yaml
or compose.yml
https://docs.docker.com/compose/compose-file/
In a Compose File, Is this path, in VOLUMES, valid for a windows as a linux enviroment?
yaml volumes: - ./mypath:myfile_datbase.d
YES.
Docker File need this notation and it’s able to translate the path to use the separator that OS needs (\ or /).
How can you define Services in a docker compose file
?
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 can you tell to docker compose
how to download an image and install it:
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 can you tell to docker compose
building a new image from a Dockerfile
?
Defining into the service propertyes the service’s statement build
:
YAML billingapp-back: build: context: ./java args: - JAR_FILE=*.jar
In this YAMLE segment, what is the function of context
:
YAML billingapp-back: build: context: ./java args: - JAR_FILE=*.jar
Define the conextx where de Dockerfile
is in reference of the path where the docker-compose
is executed.
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
~~~
- 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.
- The first path is local directory which will be accessed through the container’s directory.
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
~~~
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=””
~~~
In this service declaration, what is the function of depends_on
property?
```YAML
billingapp-back:
build:
context: ./java
args:
- JAR_FILE=*.jar
container_name: billingApp-back
depends_on:
- postgres_db
ports:
- 8080:8080
~~~
- 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
~~~
What is the command to “compile” and build service from a docker-compose YAML file?
docker-compose -f <file.yaml> build
How to initialize (run) all the services defined ina Docker Compose File (YAML) and deatach from console?
docker-compose -f <file.yaml> up -d
-d is for deatach the proccess from console.