docker service create
命令用于创建服务。按照指定参数的描述创建一个服务。必须在管理器节点上运行此命令。
用法
docker service create [OPTIONS] IMAGE [COMMAND] [ARG...]
选项
名称,简写 | 默认 | 说明 |
---|---|---|
--constraint |
Placement constraints | |
--container-label |
Container labels | |
--dns |
Set custom DNS servers | |
--dns-option |
Set DNS options | |
--dns-search |
Set custom DNS search domains | |
--endpoint-mode |
Endpoint mode (vip or dnsrr) | |
--env , -e |
Set environment variables | |
--env-file |
Read in a file of environment variables | |
--group |
Set one or more supplementary user groups for the container | |
--health-cmd |
Command to run to check health | |
--health-interval |
Time between running the check (ns/us/ms/s/m/h) | |
--health-retries |
0 | Consecutive failures needed to report unhealthy |
--health-timeout |
Maximum time to allow one check to run (ns/us/ms/s/m/h) | |
--host |
Set one or more custom host-to-IP mappings (host:ip) | |
--hostname |
Container hostname | |
--label , -l |
Service labels | |
--limit-cpu |
0.000 | Limit CPUs |
--limit-memory |
0 B | Limit Memory |
--log-driver |
Logging driver for service | |
--log-opt |
Logging driver options | |
--mode |
replicated | Service mode (replicated or global) |
--mount |
Attach a filesystem mount to the service | |
--name |
Service name | |
--network |
Network attachments | |
--no-healthcheck |
false | Disable any container-specified HEALTHCHECK |
--publish , -p |
Publish a port as a node port | |
--replicas |
Number of tasks | |
--reserve-cpu |
0.000 | Reserve CPUs |
--reserve-memory |
0 B | Reserve Memory |
--restart-condition |
Restart when condition is met (none, on-failure, or any) | |
--restart-delay |
Delay between restart attempts (ns/us/ms/s/m/h) | |
--restart-max-attempts |
Maximum number of restarts before giving up | |
--restart-window |
Window used to evaluate the restart policy (ns/us/ms/s/m/h) | |
--secret |
Specify secrets to expose to the service | |
--stop-grace-period |
Time to wait before force killing a container (ns/us/ms/s/m/h) | |
--tty , -t |
false | Allocate a pseudo-TTY |
--update-delay |
0s | Delay between updates (ns/us/ms/s/m/h) (default 0s) |
--update-failure-action |
pause | Action on update failure (pause/continue) |
--update-max-failure-ratio |
0 | Failure rate to tolerate during an update |
--update-monitor |
0s | Duration after each task update to monitor for failure (ns/us/ms/s/m/h) (default 0s) |
--update-parallelism |
1 | Maximum number of tasks updated simultaneously (0 to update all at once) |
--user , -u |
Username or UID (format: |
|
--with-registry-auth |
false | Send registry authentication details to swarm agents |
--workdir , -w |
Working directory inside the container |
相关命令
命令 | 描述 |
---|---|
docker service create | |
docker service inspect | |
docker service logs | 获取服务的日志 |
docker service ls | 列出服务 |
docker service rm | 删除一个或多个服务 |
docker service scale | 缩放一个或多个复制服务 |
docker service update | 更新服务 |
示例
创建一个服务 -
$ docker service create --name redis redis:3.0.6
dmu1ept4cxcfe8k8lhtux3ro3
$ docker service create --mode global --name redis2 redis:3.0.6
a8q9dasaafudfs8q8w32udass
$ docker service ls
ID NAME MODE REPLICAS IMAGE
dmu1ept4cxcf redis replicated 1/1 redis:3.0.6
a8q9dasaafud redis2 global 1/1 redis:3.0.6