Docker-Compose

Commandes courantes

up : Permet la création d'une application (services, volumes, réseaux)

down : Permet la suppréssion d'une application (services, volumes, réseaux)

start : Démarre une application

stop : Arrête une application

build : Build des images des services (si l'instruction build est utilisée)

pull : Téléchargement d'une image

logs : Visualisation des logs de l'application

scale : Modification du nombre de container pour un service

ps : Liste les container de l'application

Exemple d'usage

Téléchargement de l'application Voting App

git clone https://github.com/docker/example-voting-app/ && cd example-voting-app

Création de l'application

sudo docker-compose -f docker-stack.yml up -d

Creating network "example-voting-app_frontend" with the default driver
Creating network "example-voting-app_backend" with the default driver
Creating network "example-voting-app_default" with the default driver
Creating volume "example-voting-app_db-data" with default driver
Pulling redis (redis:alpine)...
alpine: Pulling from library/redis
aad63a933944: Pull complete
541cb024bf66: Pull complete
270420c343f3: Pull complete
8dd6c66eb1b0: Pull complete
782d2f0df1b3: Pull complete
b0648f46f4c9: Pull complete
...
Digest: sha256:bc680132f772cb44062795c514570db2f0b6f91063bc3afa2386edaaa0ef0b20
Status: Downloaded newer image for dockersamples/visualizer:stable
Creating example-voting-app_redis_1 ... done
Creating example-voting-app_visualizer_1 ... done
Creating example-voting-app_db_1 ... done
Creating example-voting-app_result_1 ... done
Creating example-voting-app_worker_1 ... done
Creating example-voting-app_vote_1 ... done

Liste des containers de l'application

sudo docker-compose -f docker-stack.yml ps

Name Command State Ports
-------------------------------------------------------------------------------------------------
example-voting-app_db_1 docker-entrypoint.sh postgres Up 5432/tcp
example-voting-app_redis_1 docker-entrypoint.sh redis ... Up 6379/tcp
example-voting-app_result_1 node server.js Up 0.0.0.0:5001->80/tcp
example-voting-app_visualizer_1 npm start Up 0.0.0.0:8080->8080/tcp
example-voting-app_vote_1 gunicorn app:app -b 0.0.0. ... Up 0.0.0.0:5000->80/tcp
example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up

Lancement de l'application

sudo docker-compose -f docker-stack.yml start

Starting redis ... done
Starting db ... done
Starting vote ... done
Starting result ... done
Starting worker ... done
Starting visualizer ... done

Arret de l'application

sudo docker-compose -f docker-stack.yml stop

Stopping example-voting-app_vote_1 ... done
Stopping example-voting-app_worker_1 ... done
Stopping example-voting-app_result_1 ... done
Stopping example-voting-app_db_1 ... done
Stopping example-voting-app_redis_1 ... done
Stopping example-voting-app_visualizer_1 ... done

Scale le nombre d'instance du service worker

sudo docker-compose -f docker-stack.yml up --scale worker=3

Starting example-voting-app_redis_1 ... done
Starting example-voting-app_visualizer_1 ... done
Starting example-voting-app_db_1 ... done
Starting example-voting-app_vote_1 ... done
Starting example-voting-app_result_1 ... done
Starting example-voting-app_worker_1 ... done
Creating example-voting-app_worker_2 ... done
Creating example-voting-app_worker_3 ... done
...
visualizer_1 | npm info it worked if it ends with ok
visualizer_1 | npm info using [email protected]
visualizer_1 | npm info using [email protected]
visualizer_1 | npm info lifecycle [email protected]~prestart: [email protected]
visualizer_1 | npm info lifecycle [email protected]~start: [email protected]
visualizer_1 |
visualizer_1 | > [email protected] start /app
visualizer_1 | > node server.js
visualizer_1 |
visualizer_1 | undefined
vote_1 | [2020-04-10 18:43:18 +0000] [1] [INFO] Starting gunicorn 19.6.0
worker_1 | Waiting for db
vote_1 | [2020-04-10 18:43:18 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
vote_1 | [2020-04-10 18:43:18 +0000] [1] [INFO] Using worker: sync
vote_1 | [2020-04-10 18:43:18 +0000] [10] [INFO] Booting worker with pid: 10
vote_1 | [2020-04-10 18:43:18 +0000] [11] [INFO] Booting worker with pid: 11
vote_1 | [2020-04-10 18:43:18 +0000] [16] [INFO] Booting worker with pid: 16
vote_1 | [2020-04-10 18:43:18 +0000] [17] [INFO] Booting worker with pid: 17
...

Suppression de l'application

sudo docker-compose -f docker-stack.yml down

o deploy to a swarm.
Removing example-voting-app_worker_3 ... done
Removing example-voting-app_worker_2 ... done
Removing example-voting-app_vote_1 ... done
Removing example-voting-app_worker_1 ... done
Removing example-voting-app_result_1 ... done
Removing example-voting-app_db_1 ... done
Removing example-voting-app_redis_1 ... done
Removing example-voting-app_visualizer_1 ... done
Removing network example-voting-app_frontend
Removing network example-voting-app_backend
Removing network example-voting-app_default