본문 바로가기
Tech/Containers

Docker Swarm 설치하기

by 타이호 2017. 12. 24.
반응형

1. Docker 설치

# sudo apt update
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# sudo apt update
# sudo apt-get install docker-ce
# sudo docker run hello-world

제대로 설치 되면 아래와 같이 나온다


Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/


2. docker 에러

/etc/docker/daemon.json을 넣고 나서 docker를 restart하게 되면 아래와 같이 에러가 난다.

# systemctl start docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

systemd의 docker.service를 아래와 같이 수정한다.

/lib/systemd/system/docker.service

기존의 ExecStart=/usr/bin/dockerd -H fd:// 를 아래와 같이 수정한다.
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -s overlay

/etc/docker/daemon.json을 삭제 하고 systemctl daemon-reload 를 한 후  docker를 restart한다.

 

3. docker swarm 구성

manager 1대, worker 2대로 구성을 해 본다.  환경은 vmware에 juju를 통해 3대를 ubuntu로 deploy 했다

thkang0@DESKTOP-N3FQB50:/mnt/c/Users/kth$ juju status
Model                      Controller                                                          Cloud/Region Version                                              SLA
default                    myvcenter-Openops-Datacenter            myvcenter/Openops-Datacenter 2.2.2           unsupportedApp Version Status Scale Charm Store Rev OS Notes

Unit      Workload         Agent         Machine                Public address             Ports          Message

Machine    State            DNS                                            Inst id                             Series            AZ Message
3                   started       192.168.7.28                           juju-aad7e2-3             xenial           poweredOn
4                   started      192.168.7.31                           juju-aad7e2-4             xenial           poweredOn
5                   started      192.168.7.29                          juju-aad7e2-5             xenial           poweredOn

Initialize swarm

# docker swarm init

만약 multiple interface로 구성되었을 경우 아래 옵션을 주고 네트워크를 지정해야 한다.

--advertise-addr <MANAGER-IP>

initialize가 되고 나면 docker swarm에 join할 수 있는 token이 발행된다 (docker swarm join --token xxxxxxxxxxxxxxxxxxxxxxxxxxxxx). 위와 같이 결과가 나오면 work로 사용할 노드  (3, 4 번 머신)에서 아래를 수행해야 한다.

수행하기 전에 manager 노드에서 아래 명령을 수행한다.

docker swarm join-token worker

그리고 나서 work node 두대에서 swarm join을 한다.

docker swarm join --token SWMTKN-1-62ecjm7y6664gi80edojyocv4m2jl6ehrowpjjx4jc41ph0x3b-d4oxeswwlevj22dtfjlo1j6qv 192.168.7.28:2377

 

위 과정까지 끝낸 후 manager에서 docker node ls를 수행하면 아래와 같이 정상적으로 등록이 된 것을 확인 할 수 있다.

root@juju-aad7e2-3:~# docker node ls
ID                                                                   HOSTNAME                       STATUS                       AVAILABILITY                       MANAGER                       STATUS
96m749eihupz6t107jqdri3y2            juju-aad7e2-4                   Ready                          Active
k2x3b65dzi9pwy3oyimy4dctw         juju-aad7e2-5                  Ready                          Active
te450hznziwe8sfp74acpcams  *      juju-aad7e2-3                   Ready                         Active                                       Leader

반응형