DOCKER SERVICE CREATE
Commande : docker service create
Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG...] Create a new service Options: --config config Specify configurations to expose to the service --constraint list Placement constraints --container-label list Container labels --credential-spec credential-spec Credential spec for managed service account (Windows only) -d, --detach Exit immediately instead of waiting for the service to converge --dns list Set custom DNS servers --dns-option list Set DNS options --dns-search list Set custom DNS search domains --endpoint-mode string Endpoint mode (vip or dnsrr) (default "vip") --entrypoint command Overwrite the default ENTRYPOINT of the image -e, --env list Set environment variables --env-file list Read in a file of environment variables --generic-resource list User defined resources --group list Set one or more supplementary user groups for the container --health-cmd string Command to run to check health --health-interval duration Time between running the check (ms|s|m|h) --health-retries int Consecutive failures needed to report unhealthy --health-start-period duration Start period for the container to initialize before counting retries towards unstable (ms|s|m|h) --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) --host list Set one or more custom host-to-IP mappings (host:ip) --hostname string Container hostname --init Use an init inside each service container to forward signals and reap processes --isolation string Service container isolation mode -l, --label list Service labels --limit-cpu decimal Limit CPUs --limit-memory bytes Limit Memory --log-driver string Logging driver for service --log-opt list Logging driver options --mode string Service mode (replicated or global) (default "replicated") --mount mount Attach a filesystem mount to the service --name string Service name --network network Network attachments --no-healthcheck Disable any container-specified HEALTHCHECK --no-resolve-image Do not query the registry to resolve image digest and supported platforms --placement-pref pref Add a placement preference -p, --publish port Publish a port as a node port -q, --quiet Suppress progress output --read-only Mount the container's root filesystem as read only --replicas uint Number of tasks --reserve-cpu decimal Reserve CPUs --reserve-memory bytes Reserve Memory --restart-condition string Restart when condition is met ("none"|"on-failure"|"any") (default "any") --restart-delay duration Delay between restart attempts (ns|us|ms|s|m|h) (default 5s) --restart-max-attempts uint Maximum number of restarts before giving up --restart-window duration Window used to evaluate the restart policy (ns|us|ms|s|m|h) --rollback-delay duration Delay between task rollbacks (ns|us|ms|s|m|h) (default 0s) --rollback-failure-action string Action on rollback failure ("pause"|"continue") (default "pause") --rollback-max-failure-ratio float Failure rate to tolerate during a rollback (default 0) --rollback-monitor duration Duration after each task rollback to monitor for failure (ns|us|ms|s|m|h) (default 5s) --rollback-order string Rollback order ("start-first"|"stop-first") (default "stop-first") --rollback-parallelism uint Maximum number of tasks rolled back simultaneously (0 to roll back all at once) (default 1) --secret secret Specify secrets to expose to the service --stop-grace-period duration Time to wait before force killing a container (ns|us|ms|s|m|h) (default 10s) --stop-signal string Signal to stop the container -t, --tty Allocate a pseudo-TTY --update-delay duration Delay between updates (ns|us|ms|s|m|h) (default 0s) --update-failure-action string Action on update failure ("pause"|"continue"|"rollback") (default "pause") --update-max-failure-ratio float Failure rate to tolerate during an update (default 0) --update-monitor duration Duration after each task update to monitor for failure (ns|us|ms|s|m|h) (default 5s) --update-order string Update order ("start-first"|"stop-first") (default "stop-first") --update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) (default 1) -u, --user string Username or UID (format:[: ]) --with-registry-auth Send registry authentication details to swarm agents -w, --workdir string Working directory inside the container
Créer un nouveau service en ligne de commande
docker service create [OPTIONS] image [command] [ARG...]
ex :
Ci-dessous nous créons un service constitué de 6 tâches réparties sur 4 nodes.
$ docker service create --name vote --publish 8080:80 --replicas 6 instavote/vote
w6oq3h8zshjb4rxglhax6b6us
overall progress: 6 out of 6 tasks
1/6: running [==================================================>]
2/6: running [==================================================>]
3/6: running [==================================================>]
4/6: running [==================================================>]
5/6: running [==================================================>]
6/6: running [==================================================>]
verify: Service converged
$ docker service ps vote
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
u6ft5zbc8xwz vote.1 instavote/vote:latest node3 Running Running 29 seconds ago
diftv07phzat vote.2 instavote/vote:latest node2 Running Running 27 seconds ago
k6qtg2kiewxx vote.3 instavote/vote:latest node3 Running Running 29 seconds ago
9t09sz9pr4e1 vote.4 instavote/vote:latest node4 Running Running 28 seconds ago
g7dbwtofnrmt vote.5 instavote/vote:latest node1 Running Running 26 seconds ago
m9vthhag9a1o vote.6 instavote/vote:latest node2 Running Running 27 seconds ago
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
w6oq3h8zshjb vote replicated 6/6 instavote/vote:latest *:8080->80/tcp
Exemples divers :
$ docker service create --mode global --name redis2 redis:3.0.6 $ docker service create --name redis --replicas=5 redis:3.0.6 $ docker service create --name redis --secret secret.json redis:3.0.6 $ docker service create --name redis --hostname myredis redis:3.0.6
Créer un nouveau service en montant un volume
docker service create [OPTIONS] --mount type=volume|bind,,destination=/path/in/container[,options] image [command] [ARG...]
ex :
Volume nommé :
$ docker service create \
--name my-service \
--replicas 3 \
--mount type=volume,source=my-volume,destination=/path/in/container,volume-label="color=red",volume-label="shape=round" \
nginx:alpine
Volume anonyme :
$ docker service create \
--name my-service \
--replicas 3 \
--mount type=volume,destination=/path/in/container \
nginx:alpine
Volume de type bind :
$ docker service create \
--name my-service \
--mount type=bind,source=/path/on/host,destination=/path/in/container \
nginx:alpine
Créer un nouveau service en spécifiant le mappage de ports
Format court :
docker service create [OPTIONS] --publish port:port image [command] [ARG...]
Format long :
docker service create [OPTIONS] --publish published=port,target=port image [command] [ARG...]
ex :
Ci-dessous nous créons un service constitué de 6 tâches réparties sur 4 nodes.
$ docker service create --name my_web --replicas 3 --publish 8080:80 nginx
Equivaut à :
$ docker service create --name my_web --replicas 3 --publish published=8080,target=80 nginx