install docker swarm on centos

ref:

https://sonnguyen.ws/install-docker-docker-swarm-centos7/

https://hostadvice.com/how-to/how-to-setup-docker-swarm-cluster-on-centos-7/

install docker repo

sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

 only download by:

sudo yum -y --downloadonly --downloaddir=~/docker/ install  docker-engine

install by:

sudo systemctl start docker
sudo systemctl status docker

change ExecStart

sed -i -E "s/ExecStart=(.*)/ExecStart=\1 -H tcp:\/\/0.0.0.0:2375/" /usr/lib/systemd/system/docker.service

 

install swarm

docker pull swarm

systemctl daemon-reload
systemctl restart docker

TOKEN=`sudo docker run --rm swarm create`


docker run -d --name swarm_joiner swarm join \
        --addr=0.0.0.0:2375 \
        token://acdb9dfa3ea6da0b0cfb2c819385fcd3

docker run -d -p 12375:2375 swarm manage token://acdb9dfa3ea6da0b0cfb2c819385fcd3

 

sudo docker swarm init
Swarm initialized: current node (bd58valz82l3i8fburqy0bfwi) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-1zp9h6jfc7l9auh55krtxlfca3sqcgr9tytfy99wmc93vvurwl-8mf3qdpwmgiha4s8m9aiyt8ka \
    10.0.0.65:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

 

docker swarm join \
>     --token SWMTKN-1-1zp9h6jfc7l9auh55krtxlfca3sqcgr9tytfy99wmc93vvurwl-8mf3qdpwmgiha4s8m9aiyt8ka \
>     10.0.0.65:2377
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.29/swarm/join: dial unix /var/run/docker.sock: connect: permission denied
[centos@centos-mxh ~]$ sudo docker swarm join     --token SWMTKN-1-1zp9h6jfc7l9auh55krtxlfca3sqcgr9tytfy99wmc93vvurwl-8mf3qdpwmgiha4s8m9aiyt8ka     10.0.0.65:2377
Error response from daemon: This node is already part of a swarm. Use "docker swarm leave" to leave this swarm and join another one.

 

docker swarm join-token manager

 

TOKEN=`sudo docker swarm join-token manager -q`

 

docker official doc

https://docs.docker.com/engine/swarm/swarm-tutorial/create-swarm/

 

docker rm

https://stackoverflow.com/questions/35122773/single-command-to-stop-and-remove-docker-container

 

这个还介绍了overlay 网络

https://mshk.top/2016/12/centos-docker-swarm/

 

使用Docker Swarm和DigitalOcean创建一组Docker容器

https://www.howtoing.com/how-to-create-a-cluster-of-docker-containers-with-docker-swarm-and-digitalocean-on-centos-7

https://www.digitalocean.com/community/tutorials/how-to-create-a-cluster-of-docker-containers-with-docker-swarm-and-digitalocean-on-centos-7

 

How to Install and Configure Docker Swarm on CentOS 7 / Ubuntu 16.04 / Fedora 26/25

centos7搭建Docker Swarm 集群

 

安装swarm 及其UI

http://blog.51cto.com/wangzhijian/1953677

 

Docker 打包

导出image

# source host
sudo docker images
sudo docker save -o  portainer.tar portainer/portainer
sudo docker save -o  swarm.tar swarm

导出container  (export & import)

 

两者区别 

 

Docker cmd(org)

install

#!/bin/bash
set -x -v

get_image_id(){
    STR=`tar xf $1 manifest.json -O`
    STR=${STR%%.json*}
    STR=${STR##*Config\":\"}
    STR=${STR:0:12}
    eval "$2=$STR"
}

image_id=''
get_image_id *portainer.tar image_id
echo $image_id
get_image_id *swarm.tar image_id
echo $image_id

useradd user
passwd user << EOF
123456
123456
EOF


systemctl enable sshd
systemctl start sshd
systemctl status sshd

systemctl enable docker
systemctl start docker
systemctl status docker

docker image load < *.portainer.tar
PORTAINER_IMG_ID=`ls *.portainer.tar| cut -d'.' -f1`
echo "portainer iamge id is: $PORTAINER_IMG_ID"
docker tag $PORTAINER_IMG_ID portainer/portainer:latest

docker image load < *.swarm.tar
SWARM_ID=`ls *.swarm.tar| cut -d'.' -f1`
echo "swarm iamge id is: $SWARM_ID"
docker tag $SWARM_ID swarm:latest

docker swarm init
TOKEN=`sudo docker swarm join-token manager -q`
echo "docker swarm manager token is: $TOKEN"

docker service create --name portainer --publish 9000:9000 --replicas=1 \
  --constraint 'node.role == manager' \
  --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \
  --mount type=volume,src=portainer_data,dst=/data portainer/portainer \
  -H unix:///var/run/docker.sock
                                   

 

How can I configure my reverse proxy to serve Portainer?

https://jmkhael.io/deploying-play-with-docker-com-on-my-machine/

posted @ 2018-07-30 18:05  lvmxh  阅读(284)  评论(0编辑  收藏  举报