【Docker】공식 튜토리얼을 해 보았다 【Part4】
소개
환경
튜토리얼
Part 2: Containers
Part 3: Services
Part 4: Swarms
Part 4: Swarms
클러스터 만들기
$ docker-machine create --driver virtualbox myvm1
$ docker-machine create --driver virtualbox myvm2
이런 식으로
myvm1
와 myvm2
가 작성되고 있다docker-machine ls
에서 확인 $ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v17.03.2-ce
myvm1 - virtualbox Running tcp://192.168.99.103:2376 v17.03.2-ce
myvm2 - virtualbox Running tcp://192.168.99.104:2376 v17.03.2-ce
myvm1을 Swarm Manager로 설정
$ docker-machine ssh myvm1 "docker swarm init"
Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (10.0.2.15 on eth0 and 192.168.99.103 on eth1) - specify one with --advertise-addr
exit status 1
--advertise-addr
옵션을 사용하여 다시 실행 $ docker-machine ssh myvm1 "docker swarm init --advertise-addr 192.168.99.103:2377"
Swarm initialized: current node (yfbk30ncvzp8gn60oeye6lxmn) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-5kwikrks7ukdmn02lpxu19ybpdh2xgsporxf3twyqhgnlm5sxt-6xuh5cjwfwmncu4n4aeghvfqw \
192.168.99.103:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
myvm2를 Swam 작업자로 참여
$ docker-machine ssh myvm2 "docker swarm join \
--token SWMTKN-1-5kwikrks7ukdmn02lpxu19ybpdh2xgsporxf3twyqhgnlm5sxt-6xuh5cjwfwmncu4n4aeghvfqw \
192.168.99.103:2377"
This node joined a swarm as a worker.
docker-machine ssh 명령으로 노드 확인
$ docker-machine ssh myvm1 "docker node ls"
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
8l9qvm98lmu2k4gyhnfpx83zs myvm2 Ready Active
yfbk30ncvzp8gn60oeye6lxmn * myvm1 Ready Active Leader
클러스터에 앱 배포
Part3 에서 사용한
docker-compose.yml
를 myvm1
에 복사 $ docker-machine scp docker-compose.yml myvm1:~
docker-compose.yml 100% 299 0.3KB/s 00:00
docker stack deploy
명령으로 앱 배포 $ docker-machine ssh myvm1 "docker stack deploy -c docker-compose.yml getstartedlab"
Creating network getstartedlab_webnet
Creating service getstartedlab_web
$ docker-machine ssh myvm1 "docker stack ps getstartedlab"
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
2nzqlikufmv7 getstartedlab_web.1 tocyuki/repository:tag myvm2 Running Running about a minute ago
vnx6ytymitk8 getstartedlab_web.2 tocyuki/repository:tag myvm1 Running Running about a minute ago
d77gpo4op9l8 getstartedlab_web.3 tocyuki/repository:tag myvm2 Running Running about a minute ago
0bs7md3ffa5l getstartedlab_web.4 tocyuki/repository:tag myvm1 Running Running about a minute ago
vml7gktru257 getstartedlab_web.5 tocyuki/repository:tag myvm1 Running Running about a minute ago
각 VM에 대한 부팅 상태
myvm1
$ docker-machine ssh myvm1 "docker ps"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bd811d21d9b1 tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8 "python app.py" 32 minutes ago Up 32 minutes 80/tcp getstartedlab_web.5.vml7gktru257n7p49g9typkgl
b17c0abc447c tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8 "python app.py" 32 minutes ago Up 32 minutes 80/tcp getstartedlab_web.4.0bs7md3ffa5l9jx9422lmc67c
ff50c29c1aa6 tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8 "python app.py" 32 minutes ago Up 32 minutes 80/tcp getstartedlab_web.2.vnx6ytymitk84stdi4f901ha8
myvm2
$ docker-machine ssh myvm2 "docker ps"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c6060d9c56e2 tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8 "python app.py" 34 minutes ago Up 34 minutes 80/tcp getstartedlab_web.3.d77gpo4op9l8s00u9ish4c00z
833c7cbc9ede tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8 "python app.py" 34 minutes ago Up 34 minutes 80/tcp getstartedlab_web.1.2nzqlikufmv7bwtcq2wtydzrg
액세스 이미지
myvm1
스택 폐기
$ docker-machine ssh myvm1 "docker stack rm getstartedlab"
Removing service getstartedlab_web
Removing network getstartedlab_webnet
$ docker-machine ssh myvm1 "docker stack ps getstartedlab"
Nothing found in stack: getstartedlab
Part4에서 배운 명령의 치트 시트
# Create a VM (Mac, Win7, Linux)
docker-machine create --driver virtualbox myvm1
# Win10
docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1
# View basic information about your node
docker-machine env myvm1
# List the nodes in your swarm
docker-machine ssh myvm1 "docker node ls"
# Inspect a node
docker-machine ssh myvm1 "docker node inspect <node ID>"
# View join token
docker-machine ssh myvm1 "docker swarm join-token -q worker"
# Open an SSH session with the VM; type "exit" to end
docker-machine ssh myvm1
# Make the worker leave the swarm
docker-machine ssh myvm2 "docker swarm leave"
# Make master leave, kill swarm
docker-machine ssh myvm1 "docker swarm leave -f"
# Start a VM that is currently not running
docker-machine start myvm1
# Stop all running VMs
docker-machine stop $(docker-machine ls -q)
# Delete all VMs and their disk images
docker-machine rm $(docker-machine ls -q)
# Copy file to node's home dir
docker-machine scp docker-compose.yml myvm1:~
# Deploy an app
docker-machine ssh myvm1 "docker stack deploy -c <file> <app>"
Reference
이 문제에 관하여(【Docker】공식 튜토리얼을 해 보았다 【Part4】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Tocyuki/items/dade81596400b80b7ef3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)