docker swarm

集群管理

Initialize a swarm. The docker engine targeted by this command becomes a manager in the newly created single-node swarm.

  • docker swarm init
  • docker swarm join --token SWMTKN-1-55g0lk1oofqdmf6adpn4idy7wxvql65t6rlhmq0khwlmwq5t6j-bkijx6trp01n8fn3hwhf5h7ap 10.10.1.195:2377

To remove worker2, issue the following command from worker2 itself:

  • docker swarm leave
    Remove one or more nodes from the swarm
  • docker node rm
  • docker node ls
  • docker swarm leave --force

service

  • docker service create --name busybox busybox:latest sh -c “while true; do sleep 3600; done”
  • docker service ls
  • docker service ps busybox
    当前busybox这个service的task只有1个,扩展为5个。
  • docker service scale busybox=5
    当某个task对应的容器挂掉时,会自动在任一节点启动该task对应的容器。
  • docker service ps busybox
  • docker rm -f 7d013a7eb685
  • docker service create --name nginx-service --host foo:10.0.1.30 --network swarm-net --constraint node.hostname==p09 --replicas 1 nginx:latest
  • docker service update --host-rm foo:127.0.0.1 my-service
  • docker service update --host-add foo:127.0.0.2 my-service
    -docker service inspect --format ‘{{.Spec.TaskTemplate.ContainerSpec.Hosts}}’ my-service
  • 查看端口映射
    docker port a7dafeccf24e
    [127.0.0.2 foo]
  • docker service ls
    删除service
  • docker service rm busybox
    inspect
  • docker service inspect hadoop-master

删除所有服务:

  • docker service rm $(docker service ls)

volume

https://docker-docs.netlify.app/engine/reference/commandline/service_create/#options

  • docker volume create my-vol
- 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
docker service create \
--name nginx -p 80:80 \
-m type=bind,source=/Users/beenanner/Documents,target=/documents,writable=false \
-m type=bind,source=/Users/beenanner/Pictures,target=/images,writable=true \
nginx

For each replica of the service, the engine requests a volume named “my-volume” from the default (“local”) volume driver where the task is deployed. If the volume does not exist, the engine creates a new volume and applies the “color” and “shape” labels.

When the task is started, the volume is mounted on /path/in/container/ inside the container.

Be aware that the default (“local”) volume is a locally scoped volume driver. This means that depending on where a task is deployed, either that task gets a new volume named “my-volume”, or shares the same “my-volume” with other tasks of the same service. Multiple containers writing to a single shared volume can cause data corruption if the software running inside the container is not designed to handle concurrent processes writing to the same location. Also take into account that containers can be re-scheduled by the Swarm orchestrator and be deployed on a different node.

The following example bind-mounts a host directory at /path/in/container in the containers backing the service:

$ docker service create \
  --name my-service \
  --mount type=bind,source=/path/on/host,destination=/path/in/container \
  nginx:alpine

network

  • docker network ls
  • docker network create -d overlay test
  • docker network create -d overlay swarm-net
  • docker service create --name mysql --network test -e
  • docker service inspect --format=“{{json .Endpoint.Spec.Ports}}” master
    MYSQL_ROOT_PASSWORD=123456789 -e MYSQL_DATABASE=wordpress --mount type=volume,source=mysql_data,destination=/var/lib/mysql mysql:5.7
  • docker network create -d overlay test
  • docker service ps mysql
    创建wordpress service:
  • docker service create --name wordpress --network test -p 80:80 -e WORDPRESS_DB_PASSWORD=123456789 -e WORDPRESS_DB_HOST=mysql wordpress
  • docker service ps wordpress

hadoop swarm 集群

hadoop-master

docker service create \
	--name slave4 \
	--hostname slave4 \
	--network swarm-net \
	--replicas 1 \
	--endpoint-mode dnsrr \
	hadoop2.7-v1
docker service create \
	--name slave4 \
	--hostname slave4 \
	--network swarm-net \
	--replicas 1 \
	--endpoint-mode dnsrr \
	registry.cn-hangzhou.aliyuncs.com/ruiclear/clean-hadoop:1.0.0

hadoop-slave1

docker service create \
	--name p09 \
	--hostname p09 \
	--network swarm-net \
	--replicas 1 \
	--endpoint-mode dnsrr \
	hadoop2.7-v1
docker service create \
	--name hadoop-slave1 \
	--hostname hadoop-slave1 \
	--network swarm-net \
	--replicas 1 \
	--endpoint-mode dnsrr \
	registry.cn-hangzhou.aliyuncs.com/ruiclear/clean-hadoop:1.0.0

docker service create \
	--name hadoop-master \
	--hostname hadoop-master \
	--network swarm-net \
	--constraint node.hostname==slave4 \
	--replicas 1 \
	--endpoint-mode dnsrr \
	lilelr/lele_hadoop2.7:1.0
	
docker service create \
	--name hadoop-slave1 \
	--hostname hadoop-slave1 \
	--network swarm-net \
	--constraint node.hostname==p09 \
	--replicas 1 \
	--endpoint-mode dnsrr \
	lilelr/lele_hadoop2.7:1.0
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值