Docker 1.12 版本 Docker Swarm 集群(2)

[root@swarm-manager ~]#docker service --help Usage: docker service COMMAND Manage Docker services Options: --help Print usage Commands: create Create a new service inspect Inspect a service tasks List the tasks of a service ls List services rm Remove a service scale Scale one or multiple services update Update a service Run 'docker service COMMAND --help' for more information on a command.

1. docker create 命令, 既 创建 一个 服务。

[root@swarm-manager ~]#docker service create --help Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG...] Create a new service Options: --constraint value Placement constraints (default []) --endpoint-mode string Endpoint mode(Valid values: VIP, DNSRR) -e, --env value Set environment variables (default []) --help Print usage -l, --label value Service labels (default []) --limit-cpu value Limit CPUs (default 0.000) --limit-memory value Limit Memory (default 0 B) --mode string Service mode (replicated or global) (default "replicated") -m, --mount value Attach a mount to the service --name string Service name --network value Network attachments (default []) -p, --publish value Publish a port as a node port (default []) --replicas value Number of tasks (default none) --reserve-cpu value Reserve CPUs (default 0.000) --reserve-memory value Reserve Memory (default 0 B) --restart-condition string Restart when condition is met (none, on_failure, or any) --restart-delay value Delay between restart attempts (default none) --restart-max-attempts value Maximum number of restarts before giving up (default none) --restart-window value Window used to evalulate the restart policy (default none) --stop-grace-period value Time to wait before force killing a container (default none) --update-delay duration Delay between updates --update-parallelism uint Maximum number of tasks updated simultaneously -u, --user string Username or UID -w, --workdir string Working directory inside the container

docker service create 里面有非常多的 参数。 这里有很详细的使用说明。

下面我们来 创建一个 service 试试看

首先pull 一个 nginx 镜像 下来 用于 测试

[root@swarm-manager ~]#docker pull nginx

创建 2 个 nginx :

[root@swarm-manager ~]#docker service create --name nginx --replicas 2 -p 80:80/tcp nginx

使用 docker service ls 可查看 服务 启动情况。

[root@swarm-manager ~]#docker service ls ID NAME REPLICAS IMAGE COMMAND 1b9a58mlz330 nginx 1/2 nginx

使用 tasks 命令 可查看 nginx 的情况。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/163d9f6e5ece38e97dbc170f36dc2820.html