DOCKER-COMPOSE
Define and run multi-container applications with Docker. Usage: docker-compose [-f...] [options] [COMMAND] [ARGS...] docker-compose -h|--help Options: -f, --file FILE Specify an alternate compose file (default: docker-compose.yml) -p, --project-name NAME Specify an alternate project name (default: directory name) --verbose Show more output --log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) --no-ansi Do not print ANSI control characters -v, --version Print version and exit -H, --host HOST Daemon socket to connect to --tls Use TLS; implied by --tlsverify --tlscacert CA_PATH Trust certs signed only by this CA --tlscert CLIENT_CERT_PATH Path to TLS certificate file --tlskey TLS_KEY_PATH Path to TLS key file --tlsverify Use TLS and verify the remote --skip-hostname-check Don't check the daemon's hostname against the name specified in the client certificate --project-directory PATH Specify an alternate working directory (default: the path of the Compose file) --compatibility If set, Compose will attempt to convert deploy keys in v3 files to their non-Swarm equivalent Commands: build Build or rebuild services bundle Generate a Docker bundle from the Compose file config Validate and view the Compose file create Create services down Stop and remove containers, networks, images, and volumes events Receive real time events from containers exec Execute a command in a running container help Get help on a command images List images kill Kill containers logs View output from containers pause Pause services port Print the public port for a port binding ps List containers pull Pull service images push Push service images restart Restart services rm Remove stopped containers run Run a one-off command scale Set number of containers for a service start Start services stop Stop services top Display the running processes unpause Unpause services up Create and start containers version Show the Docker-Compose version information Run 'docker-compose COMMAND --help' for more information on a command.
docker-compose [-f...] [options] [COMMAND] [ARGS...]
DOCKER-COMPOSE BUILD
Build or rebuild services. Services are built once and then tagged as `project_service`, e.g. `composetest_db`. If you change a service's `Dockerfile` or the contents of its build directory, you can run `docker-compose build` to rebuild it. Usage: build [options] [--build-arg key=val...] [SERVICE...] Options: --compress Compress the build context using gzip. --force-rm Always remove intermediate containers. --no-cache Do not use cache when building the image. --pull Always attempt to pull a newer version of the image. -m, --memory MEM Sets memory limit for the build container. --build-arg key=val Set build-time variables for services.
Construire ou reconstruire les images des services dont le Dockerfile a été modifié :
Si un Dockerfile est modifié, un docker-compose up ne le prendra pas en compte, il faut effectuer un rebuild du service correspondant (ou de tous les services).
Le cache sera utilisé jusqu’à la première ligne modifiée.
docker-compose build [SERVICE...]
ex :
$ docker-compose build
Construire ou reconstruire les images avec les dernières versions des images de base :
docker-compose build --pull [SERVICE...]
ex :
$ docker-compose build --pull
Construire ou reconstruire les images sans utiliser le cache :
docker-compose build --no-cache [SERVICE...]
ex :
$ docker-compose build --no-cache
DOCKER-COMPOSE CONFIG
Validate and view the Compose file. Usage: config [options] Options: --resolve-image-digests Pin image tags to digests. -q, --quiet Only validate the configuration, don't print anything. --services Print the service names, one per line. --volumes Print the volume names, one per line.
Pour plus d’informations sur la génération de configurations avec docker-compose, voir l’article suivant :
Docker – Mini-tutos
Vérifier la configuration et la syntaxe du fichier Docker Compose :
docker-compose config
ex :
$ docker-compose config
ERROR: yaml.scanner.ScannerError: while scanning a simple key
in "./docker-compose.yml", line 2, column 1
could not find expected ':'
in "./docker-compose.yml", line 3, column 1
Vérifier la configuration et la syntaxe du fichier Docker Compose silencieusement par le code retour :
docker-compose config -q
ex :
$ docker-compose config -q $ echo $? 0
Lister les services définis dans le fichier Docker Compose :
docker-compose config --services
Equivaut à :
docker-compose ps --services
ex :
$ docker-compose config --services
vote
result
redis
worker
db
Lister les volumes définis dans le fichier Docker Compose :
docker-compose config --services
ex :
$ docker-compose config --volumes
db-data
DOCKER-COMPOSE DOWN
Stops containers and removes containers, networks, volumes, and images created by `up`. By default, the only things removed are: - Containers for services defined in the Compose file - Networks defined in the `networks` section of the Compose file - The default network, if one is used Networks and volumes defined as `external` are never removed. Usage: down [options] Options: --rmi type Remove images. Type must be one of: 'all': Remove all images used by any service. 'local': Remove only images that don't have a custom tag set by the `image` field. -v, --volumes Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers. --remove-orphans Remove containers for services not defined in the Compose file -t, --timeout TIMEOUT Specify a shutdown timeout in seconds. (default: 10)
Arrêter les services, supprimer les containers et les réseaux de l’application :
Contrairement à la commande docker-compose stop, les containers seront non seulement arrêtés mais également supprimés.
Les réseaux définis dans le fichier docker-compose.yml seront également supprimés.
docker-compose down
ex :
$ docker-compose down
Stopping db ... done
Stopping example-voting-app_result_1 ... done
Stopping example-voting-app_vote_1 ... done
Stopping example-voting-app_worker_1 ... done
Stopping redis ... done
Removing db ... done
Removing example-voting-app_result_1 ... done
Removing example-voting-app_vote_1 ... done
Removing example-voting-app_worker_1 ... done
Removing redis ... done
Removing network example-voting-app_front-tier
Removing network example-voting-app_back-tier
$ docker-compose -f compose-sample-3/docker-compose.yml down
Arrêter les services, supprimer les containers, les réseaux et les volumes :
docker-compose down --volumes
ex :
$ docker-compose down --volumes
Stopping example-voting-app_worker_1 ... done
Stopping redis ... done
Stopping db ... done
Stopping example-voting-app_result_1 ... done
Stopping example-voting-app_vote_1 ... done
Removing example-voting-app_worker_1 ... done
Removing redis ... done
Removing db ... done
Removing example-voting-app_result_1 ... done
Removing example-voting-app_vote_1 ... done
Removing network example-voting-app_front-tier
Removing network example-voting-app_back-tier
Removing volume example-voting-app_db-data
Arrêter les services, supprimer les containers, les réseaux, les volumes et les images construites et téléchargées :
docker-compose down --volumes --rmi all
ex :
$ docker-compose down --volumes --rmi all
Stopping example-voting-app_worker_1 ... done
Stopping example-voting-app_result_1 ... done
Stopping redis ... done
Stopping example-voting-app_vote_1 ... done
Stopping db ... done
Removing example-voting-app_worker_1 ... done
Removing example-voting-app_result_1 ... done
Removing redis ... done
Removing example-voting-app_vote_1 ... done
Removing db ... done
Removing network example-voting-app_front-tier
Removing network example-voting-app_back-tier
Removing volume example-voting-app_db-data
Removing image example-voting-app_vote
Removing image example-voting-app_result
Removing image redis:alpine
Removing image example-voting-app_worker
Removing image postgres:9.4
DOCKER-COMPOSE EVENTS
Receive real time events from containers. Usage: events [options] [SERVICE...] Options: --json Output events as a stream of json objects
Recevoir les évènements en temps réels des containers :
Les évènements reçus sont du type : attach, detach, kill, pause, unpause, start, stop, top, etc.
Pour la liste complète des évènements reçus : Docker Docs – docker events
docker-compose events [--json] [SERVICE...]
ex :
$ docker-compose events
2018-10-20 23:09:26.748261 container exec_create: apk update 04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b (image=example-voting-app_result, name=example-voting-app_result_1)
2018-10-20 23:09:26.751897 container exec_start: apk update 04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b (image=example-voting-app_result, name=example-voting-app_result_1)
2018-10-20 23:09:27.886204 container exec_die 04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b (image=example-voting-app_result, name=example-voting-app_result_1)
$ docker-compose events --json
{"time": "2018-10-20T23:21:17.056049", "type": "container", "action": "exec_create: apk update", "id": "04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b", "service": "result", "attributes": {"name": "example-voting-app_result_1", "image": "example-voting-app_result"}}
{"time": "2018-10-20T23:21:17.061523", "type": "container", "action": "exec_start: apk update", "id": "04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b", "service": "result", "attributes": {"name": "example-voting-app_result_1", "image": "example-voting-app_result"}}
{"time": "2018-10-20T23:21:17.863245", "type": "container", "action": "exec_die", "id": "04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b", "service": "result", "attributes": {"name": "example-voting-app_result_1", "image": "example-voting-app_result"}}
$ docker-compose events --json | jq
{
"time": "2018-10-20T23:23:08.660013",
"type": "container",
"action": "exec_create: apk update",
"id": "04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b",
"service": "result",
"attributes": {
"name": "example-voting-app_result_1",
"image": "example-voting-app_result"
}
}
{
"time": "2018-10-20T23:23:08.666409",
"type": "container",
"action": "exec_start: apk update",
"id": "04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b",
"service": "result",
"attributes": {
"name": "example-voting-app_result_1",
"image": "example-voting-app_result"
}
}
{
"time": "2018-10-20T23:23:09.460027",
"type": "container",
"action": "exec_die",
"id": "04039d38798034c313f5465a3fd235252ae26f9476e269400d98827f13af857b",
"service": "result",
"attributes": {
"name": "example-voting-app_result_1",
"image": "example-voting-app_result"
}
}
DOCKER-COMPOSE EXEC
Execute a command in a running container Usage: exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...] Options: -d, --detach Detached mode: Run command in the background. --privileged Give extended privileges to the process. -u, --user USER Run the command as this user. -T Disable pseudo-tty allocation. By default `docker-compose exec` allocates a TTY. --index=index index of the container if there are multiple instances of a service [default: 1] -e, --env KEY=VAL Set environment variables (can be used multiple times, not supported in API < 1.25) -w, --workdir DIR Path to workdir directory for this command.
Forcer l'arrêt des containers d'une application :
docker-compose exec [options] [-e KEY=VAL...] SERVICE COMMAND [ARGS...]
ex :
$ docker-compose exec redis apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
v3.8.1-34-ga8e558ca77 [http://dl-cdn.alpinelinux.org/alpine/v3.8/main]
v3.8.1-28-g1d8df16b35 [http://dl-cdn.alpinelinux.org/alpine/v3.8/community]
OK: 9540 distinct packages available
DOCKER-COMPOSE IMAGES
List images used by the created containers. Usage: images [options] [SERVICE...] Options: -q, --quiet Only display IDs
Lister les images utilisées (téléchargées et construites) par les containers de services :
docker-compose images [SERVICE...]
ex :
$ docker-compose images Container Repository Tag Image Id Size ----------------------------------------------------------------------------------------- db postgres 9.4 7889bf54d0cf 214 MB example-voting-app_result_1 example-voting-app_result latest 25f381575994 77.5 MB example-voting-app_vote_1 example-voting-app_vote latest 9768fa953ff5 68.2 MB example-voting-app_worker_1 example-voting-app_worker latest 96ca93da0c49 1.6 GB redis redis alpine 05635ee9e1c7 39 MB $ docker-compose images db Container Repository Tag Image Id Size ---------------------------------------------------- db postgres 9.4 7889bf54d0cf 214 MB
DOCKER-COMPOSE KILL
Force stop service containers. Usage: kill [options] [SERVICE...] Options: -s SIGNAL SIGNAL to send to the container. Default signal is SIGKILL.
Forcer l'arrêt des containers d'une application :
docker-compose kill [SERVICE...]
ex :
$ docker-compose kill
Killing example-voting-app_vote_1 ... done
Killing example-voting-app_worker_1 ... done
Killing db ... done
Killing redis ... done
Killing example-voting-app_result_1 ... done
$ docker-compose kill redis Killing redis ... done $ docker-compose kill -s 15 vote Killing example-voting-app_vote_1 ... done $ docker-compose kill -s SIGTERM result Killing example-voting-app_result_1 ... done
DOCKER-COMPOSE LOGS
View output from containers. Usage: logs [options] [SERVICE...] Options: --no-color Produce monochrome output. -f, --follow Follow log output. -t, --timestamps Show timestamps. --tail="all" Number of lines to show from the end of the logs for each container.
Afficher la sortie produite par les services spécifiés :
docker-compose logs [options] [SERVICE...]
ex :
$ docker-compose logs logstash
[...]
logstash_1 | 12:55:24.411 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9600}
logstash_1 | {
logstash_1 | "request" => "/api/object/5996fc0f4c06fb000f83b7",
logstash_1 | "agent" => "\"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0\"",
logstash_1 | "minor" => "0",
logstash_1 | "auth" => "-",
logstash_1 | "ident" => "-",
logstash_1 | "type" => "nginx",
logstash_1 | "path" => "/var/log/nginx.log",
logstash_1 | "major" => "55",
logstash_1 | "clientip" => "46.218.112.178",
logstash_1 | "@version" => "1",
logstash_1 | "host" => "c8adf8edaa41",
logstash_1 | "extra_fields" => " \"-\"",
logstash_1 | "geoip" => {
logstash_1 | "timezone" => "Europe/Paris",
logstash_1 | "ip" => "46.218.112.178",
logstash_1 | "latitude" => 48.8058,
logstash_1 | "continent_code" => "EU",
logstash_1 | "city_name" => "Alfortville",
logstash_1 | "country_name" => "France",
logstash_1 | "country_code2" => "FR",
logstash_1 | "country_code3" => "FR",
logstash_1 | "region_name" => "Val-de-Marne",
logstash_1 | "location" => {
logstash_1 | "lon" => 2.4204,
logstash_1 | "lat" => 48.8058
logstash_1 | },
logstash_1 | "postal_code" => "94140",
logstash_1 | "region_code" => "94",
logstash_1 | "longitude" => 2.4204
logstash_1 | },
logstash_1 | "os" => "Windows 10",
logstash_1 | "verb" => "GET",
logstash_1 | "message" => "46.218.112.178 - - [28/Sep/2017:15:40:04 +0000] \"GET /api/object/5996fc0f4c06fb000f83b7 HTTP/1.1\" 200 501 \"https://mydomain.net/map\" \"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0\" \"-\"",
logstash_1 | "tags" => [
logstash_1 | [0] "nginx-geoip"
logstash_1 | ],
logstash_1 | "referrer" => "\"https://mydomain.net/map\"",
logstash_1 | "@timestamp" => 2017-09-28T15:40:04.000Z,
logstash_1 | "build" => "",
logstash_1 | "response" => 200,
logstash_1 | "bytes" => 501,
logstash_1 | "name" => "Firefox",
logstash_1 | "os_name" => "Windows 10",
logstash_1 | "httpversion" => "1.1",
logstash_1 | "device" => "Other"
logstash_1 | }
[...]
$ docker-compose logs -f --tail=3
Attaching to example-voting-app_worker_1, redis, db, example-voting-app_result_1, example-voting-app_vote_1
worker_1 | Connected to db
worker_1 | Found redis at 172.27.0.3
worker_1 | Connecting to redis
db | LOG: MultiXact member wraparound protections are now enabled
db | LOG: database system is ready to accept connections
db | LOG: autovacuum launcher started
vote_1 | * Restarting with stat
vote_1 | * Debugger is active!
vote_1 | * Debugger PIN: 113-172-582
result_1 | Waiting for db
result_1 | Waiting for db
result_1 | Connected to db
redis | 1:M 20 Oct 2018 20:26:38.509 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis | 1:M 20 Oct 2018 20:26:38.509 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis | 1:M 20 Oct 2018 20:26:38.509 * Ready to accept connections
DOCKER-COMPOSE PAUSE
Pause services. Usage: pause [SERVICE...]
Mettre en pause les services spécifiés :
Si aucun service n'est spécifié, tous les services de l'application seront mis en pause.
docker-compose pause [SERVICE...]
ex :
$ docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------- db docker-entrypoint.sh postgres Up 5432/tcp example-voting-app_result_1 nodemon server.js Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp example-voting-app_vote_1 python app.py Up 0.0.0.0:5000->80/tcp example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up redis docker-entrypoint.sh redis ... Up 0.0.0.0:32772->6379/tcp $ docker-compose pause vote Pausing example-voting-app_vote_1 ... done $ docker-compose ps Name Command State Ports -------------------------------------------------------------------------------------------------------------------- db docker-entrypoint.sh postgres Up 5432/tcp example-voting-app_result_1 nodemon server.js Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp example-voting-app_vote_1 python app.py Paused 0.0.0.0:5000->80/tcp example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up redis docker-entrypoint.sh redis ... Up 0.0.0.0:32772->6379/tcp
DOCKER-COMPOSE PS
List containers. Usage: ps [options] [SERVICE...] Options: -q, --quiet Only display IDs --services Display services --filter KEY=VAL Filter services by a property
Afficher la liste des containers de l'application :
docker-compose ps
ex :
$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------
db docker-entrypoint.sh postgres Up 5432/tcp
example-voting-app_result_1 nodemon server.js Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp
example-voting-app_vote_1 python app.py Up 0.0.0.0:5000->80/tcp
example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up
redis docker-entrypoint.sh redis ... Up 0.0.0.0:32782->6379/tcp
Afficher la liste des services de l'application :
Les services sont listés même si aucun container n'est démarré.
docker-compose ps --services
Equivaut à :
docker-compose config --services
ex :
$ docker-compose ps --services
vote
result
redis
worker
db
DOCKER-COMPOSE PULL
Pulls images for services defined in a Compose file, but does not start the containers. Usage: pull [options] [SERVICE...] Options: --ignore-pull-failures Pull what it can and ignores images with pull failures. --parallel Deprecated, pull multiple images in parallel (enabled by default). --no-parallel Disable parallel pulling. -q, --quiet Pull without printing progress information --include-deps Also pull services declared as dependencies
Télécharger les images de base des services sans démarrer les containers :
Les images seront téléchargées, mais aucune ne sera construite.
docker-compose pull [SERVICE...]
ex :
$ docker-compose pull
Pulling vote ... done
Pulling result ... done
Pulling redis ... done
Pulling worker ... done
Pulling db ... done
DOCKER-COMPOSE RESTART
Restart running containers. Usage: restart [options] [SERVICE...] Options: -t, --timeout TIMEOUT Specify a shutdown timeout in seconds. (default: 10)
Redémarrer des services actifs :
Si aucun service n'est spécifié, tous les services de l'application seront redémarrés.
docker-compose restart [SERVICE...]
ex :
$ docker-compose restart
Restarting example-voting-app_worker_1 ... done
Restarting db ... done
Restarting example-voting-app_result_1 ... done
Restarting example-voting-app_vote_1 ... done
Restarting redis ... done
DOCKER-COMPOSE RM
Removes stopped service containers. By default, anonymous volumes attached to containers will not be removed. You can override this with `-v`. To list all volumes, use `docker volume ls`. Any data which is not in a volume will be lost. Usage: rm [options] [SERVICE...] Options: -f, --force Don't ask to confirm removal -s, --stop Stop the containers, if required, before removing -v Remove any anonymous volumes attached to containers -a, --all Deprecated - no effect.
Supprimer les containers stoppés au préalable :
Si aucun service n'est spécifié, tous les containers stoppés de l'application seront supprimés.
docker-compose rm [SERVICE...]
ex :
$ docker-compose rm
Going to remove example-voting-app_worker_1, redis, db, example-voting-app_result_1, example-voting-app_vote_1
Are you sure? [yN] y
Removing example-voting-app_worker_1 ... done
Removing redis ... done
Removing db ... done
Removing example-voting-app_result_1 ... done
Removing example-voting-app_vote_1 ... done
Stopper et supprimer les containers :
Si aucun service n'est spécifié, tous les containers de l'application seront stoppés puis supprimés.
docker-compose rm -s [SERVICE...]
ex :
$ docker-compose rm -s
Stopping example-voting-app_worker_1 ... done
Stopping redis ... done
Stopping db ... done
Stopping example-voting-app_result_1 ... done
Stopping example-voting-app_vote_1 ... done
Going to remove example-voting-app_worker_1, redis, db, example-voting-app_result_1, example-voting-app_vote_1
Are you sure? [yN] y
Removing example-voting-app_worker_1 ... done
Removing redis ... done
Removing db ... done
Removing example-voting-app_result_1 ... done
Removing example-voting-app_vote_1 ... done
$ docker-compose rm -s vote
Stopping example-voting-app_vote_1 ... done
Going to remove example-voting-app_vote_1
Are you sure? [yN] y
Removing example-voting-app_vote_1 ... done
DOCKER-COMPOSE START
Start existing containers. Usage: start [SERVICE...]
Démarrer des services existants précédemment arrêtés :
Si aucun service n'est spécifié, tous les services de l'application seront démarrés.
docker-compose start [SERVICE...]
ex :
$ docker-compose start
Starting vote ... done
Starting result ... done
Starting redis ... done
Starting worker ... done
Starting db ... done
DOCKER-COMPOSE STOP
Stop running containers without removing them. They can be started again with `docker-compose start`. Usage: stop [options] [SERVICE...] Options: -t, --timeout TIMEOUT Specify a shutdown timeout in seconds. (default: 10)
Arrêter les services de l'application :
Si aucun service n'est spécifié, tous les containers de l'application seront arrêtés.
Les containers ne seront pas supprimés, ils pourront être redémarrés avec la commande docker-compose start.
docker-compose stop [options] [SERVICE...]
ex :
$ docker-compose stop
Stopping db ... done
Stopping example-voting-app_result_1 ... done
Stopping example-voting-app_vote_1 ... done
Stopping example-voting-app_worker_1 ... done
Stopping redis ... done
DOCKER-COMPOSE TOP
Display the running processes Usage: top [SERVICE...]
Afficher les processus en cours :
Si aucun service n'est spécifié, tous les processus en cours de tous les containers seront affichés.
docker-compose top [SERVICE...]
ex :
$ docker-compose top
db
UID PID PPID C STIME TTY TIME CMD
---------------------------------------------------------------------------------------------------------
vboxadd 16305 16244 0 22:26 ? 00:00:00 postgres
vboxadd 16866 16305 0 22:26 ? 00:00:00 postgres: checkpointer process
vboxadd 16867 16305 0 22:26 ? 00:00:00 postgres: writer process
vboxadd 16868 16305 0 22:26 ? 00:00:00 postgres: wal writer process
vboxadd 16869 16305 0 22:26 ? 00:00:00 postgres: autovacuum launcher process
vboxadd 16870 16305 0 22:26 ? 00:00:00 postgres: stats collector process
vboxadd 16872 16305 0 22:26 ? 00:00:01 postgres: postgres postgres 172.27.0.6(51422) idle
vboxadd 16876 16305 0 22:26 ? 00:00:00 postgres: postgres postgres 172.27.0.4(37812) idle
example-voting-app_result_1
UID PID PPID C STIME TTY TIME CMD
-----------------------------------------------------------------------------------------
root 16494 16456 0 22:26 ? 00:00:01 node /usr/local/bin/nodemon server.js
root 16798 16494 0 22:26 ? 00:00:00 /usr/local/bin/node server.js
example-voting-app_vote_1
UID PID PPID C STIME TTY TIME CMD
--------------------------------------------------------------------------------
root 16510 16483 0 22:26 ? 00:00:00 python app.py
root 16797 16510 1 22:26 ? 00:00:02 /usr/local/bin/python app.py
example-voting-app_worker_1
UID PID PPID C STIME TTY TIME CMD
-------------------------------------------------------------------------------------------
root 16724 16703 0 22:26 ? 00:00:00 /bin/sh -c dotnet src/Worker/Worker.dll
root 16777 16724 2 22:26 ? 00:00:04 dotnet src/Worker/Worker.dll
redis
UID PID PPID C STIME TTY TIME CMD
--------------------------------------------------------------------
systemd+ 16442 16412 0 22:26 ? 00:00:01 redis-server
DOCKER-COMPOSE UNPAUSE
Unpause services. Usage: unpause [SERVICE...]
Sortir de pause les services spécifiés :
Si aucun service n'est spécifié, tous les services de l'application seront sortis de pause.
docker-compose unpause [SERVICE...]
ex :
$ docker-compose ps Name Command State Ports -------------------------------------------------------------------------------------------------------------------- db docker-entrypoint.sh postgres Up 5432/tcp example-voting-app_result_1 nodemon server.js Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp example-voting-app_vote_1 python app.py Paused 0.0.0.0:5000->80/tcp example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up redis docker-entrypoint.sh redis ... Up 0.0.0.0:32772->6379/tcp $ docker-compose unpause vote Unpausing example-voting-app_vote_1 ... done $ docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------- db docker-entrypoint.sh postgres Up 5432/tcp example-voting-app_result_1 nodemon server.js Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp example-voting-app_vote_1 python app.py Up 0.0.0.0:5000->80/tcp example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up redis docker-entrypoint.sh redis ... Up 0.0.0.0:32772->6379/tcp
DOCKER-COMPOSE UP
Builds, (re)creates, starts, and attaches to containers for a service. Unless they are already running, this command also starts any linked services. The `docker-compose up` command aggregates the output of each container. When the command exits, all containers are stopped. Running `docker-compose up -d` starts the containers in the background and leaves them running. If there are existing containers for a service, and the service's configuration or image was changed after the container's creation, `docker-compose up` picks up the changes by stopping and recreating the containers (preserving mounted volumes). To prevent Compose from picking up changes, use the `--no-recreate` flag. If you want to force Compose to stop and recreate all containers, use the `--force-recreate` flag. Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...] Options: -d, --detach Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit. --no-color Produce monochrome output. --quiet-pull Pull without printing progress information --no-deps Don't start linked services. --force-recreate Recreate containers even if their configuration and image haven't changed. --always-recreate-deps Recreate dependent containers. Incompatible with --no-recreate. --no-recreate If containers already exist, don't recreate them. Incompatible with --force-recreate and -V. --no-build Don't build an image, even if it's missing. --no-start Don't start the services after creating them. --build Build images before starting containers. --abort-on-container-exit Stops all containers if any container was stopped. Incompatible with -d. -t, --timeout TIMEOUT Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10) -V, --renew-anon-volumes Recreate anonymous volumes instead of retrieving data from the previous containers. --remove-orphans Remove containers for services not defined in the Compose file. --exit-code-from SERVICE Return the exit code of the selected service container. Implies --abort-on-container-exit. --scale SERVICE=NUM Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.
Démarrer une application ou des services en particulier :
Si aucun service n'est spécifié, ils seront tous démarrés dans l'ordre défini par les dépendances.
Si un service est spécifié, seul lui sera démarré, sauf s'il possède un ou plusieurs dépendances, auxquels cas ces dernières seront démarrées au préalable.
Sans l'option -d, ils seront démarrés au premier-plan.
Avec l'option -d, ils seront démarrés en arrière-plan (mode detach).
Avec l'option --no-deps, les dépendances ne sont pas démarrées au préalable.
docker-compose up [options] [SERVICE...]
ex :
$ docker-compose up -d
Creating network "example-voting-app_front-tier" with the default driver
Creating network "example-voting-app_back-tier" with the default driver
Creating example-voting-app_vote_1 ... done
Creating db ... done
Creating example-voting-app_result_1 ... done
Creating redis ... done
Creating example-voting-app_worker_1 ... done
$ docker-compose up -d worker
Creating network "example-voting-app_front-tier" with the default driver
Creating network "example-voting-app_back-tier" with the default driver
Creating redis ... done
Creating example-voting-app_worker_1 ... done
$ docker-compose up -d --no-deps worker
Creating network "example-voting-app_front-tier" with the default driver
Creating network "example-voting-app_back-tier" with the default driver
Creating example-voting-app_worker_1 ... done
Démarrer une application tout en reconstruisant les images (directive build) :
docker-compose up [options] --build [SERVICE...]
ex :
$ docker-compose up -d --build
Définir le fichier Docker Compose à utiliser :
Par défaut, Docker Compose utilise le fichier docker-compose.yml situé dans le répertoire courant.
On peut toutefois spécifier un fichier alternatif avec l'option -f (--file).
docker-compose -f filename [options] [SERVICE...]
ex :
$ docker-compose -f docker-compose-simple.yml up -d
Définir le working directory à utiliser :
Par défaut, Docker Compose utilise le répertoire courant comme répertoire de travail.
On peut toutefois spécifier un répertoire de travail alternatif avec l'option --project-directory.
docker-compose --project-directory directory [options] [SERVICE...]
ex :
$ docker-compose --project-directory compose-sample-1/ --file compose-sample-1/docker-compose.yml up -d
Scaler un service :
Si le service utilise l'instruction container_name pour nommer le container correspondant, il ne pourra pas être scalé : plusieurs containers ne peuvent pas avoir le même nom
Si le service expose un port particulier, il ne pourra pas être scalé : plusieurs containers ne peuvent pas utiliser le même port de la machine hôte.
docker-compose up [options] --scale service=N [SERVICE...]
ex :
$ docker-compose up -d --scale simulator=3
iot_collector_1 is up-to-date
iot_dashboard_1 is up-to-date
influx is up-to-date
Starting iot_simulator_1 ... done
Creating iot_simulator_2 ... done
Creating iot_simulator_3 ... done
$ docker-compose up -d --scale redis=2
...
ERROR: for redis Cannot create container for service redis: Conflict. The container name "/redis" is already in use by container "ff7ffbbebc3f4441a6b93c9a06389367b552b010bd62377931372ec2da0d4d59". You have to remove (or rename) that container to be able to reuse that name.
$ docker-compose up -d --scale vote=3
...
ERROR: for examplevotingapp_vote_3 Cannot start service vote: driver failed programming external connectivity on endpoint examplevotingapp_vote_3 (b520da97c5736c46bfb2c80947fd2643387df0e0f67bbe18c226bad006dc940e): Bind for 0.0.0.0:5000 failed: port is already allocated
Recréer les containers même si leur configuration ou leur image n'a pas changé :
docker-compose up [options] --force-recreate [SERVICE...]
ex :
$ docker-compose up -d --force-recreate
Recreating example-voting-app_vote_1 ... done
Recreating db ... done
Recreating example-voting-app_result_1 ... done
Recreating redis ... done
Recreating example-voting-app_worker_1 ... done
Ne pas démarrer les containers après avoir créé les services de l'application :
L'option -d ne peut pas être utilisée avec l'option --no-start.
docker-compose up [options] --no-start [SERVICE...]
ex :
$ docker-compose up --no-start Creating network "example-voting-app_front-tier" with the default driver Creating network "example-voting-app_back-tier" with the default driver Creating example-voting-app_vote_1 ... done Creating redis ... done Creating db ... done Creating example-voting-app_result_1 ... done Creating example-voting-app_worker_1 ... done $ docker-compose ps Name Command State Ports ----------------------------------------------------------------------------- db docker-entrypoint.sh postgres Exit 0 example-voting-app_result_1 nodemon server.js Exit 0 example-voting-app_vote_1 python app.py Exit 0 example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Exit 0 redis docker-entrypoint.sh redis ... Exit 0
Construire les images avant de démarrer les containers :
docker-compose up [options] --build [SERVICE...]
ex :
$ docker-compose up -d --build
Ne pas construire les images avant de démarrer les containers même si elles sont manquantes :
docker-compose up [options] --no-build [SERVICE...]
ex :
$ docker-compose up -d --no-build
REFERENCES
- Docker Docs - docker-compose build
- Docker Docs - docker-compose config
- Docker Docs - docker-compose down
- Docker Docs - docker-compose events
- Docker Docs - docker-compose exec
- Docker Docs - docker-compose kill
- Docker Docs - docker-compose logs
- Docker Docs - docker-compose pause
- Docker Docs - docker-compose ps
- Docker Docs - docker-compose pull
- Docker Docs - docker-compose restart
- Docker Docs - docker-compose rm
- Docker Docs - docker-compose start
- Docker Docs - docker-compose stop
- Docker Docs - docker-compose top
- Docker Docs - docker-compose unpause
- Docker Docs - docker-compose up