【Docker】공식 튜토리얼을 해 보았다 【Part4】

소개


  • Conoha의 VPS를 빌렸기 때문에 Docker를 넣으려고했고 공식 튜토리얼을 시도하려고했습니다.

  • 환경


  • Windows10
  • VirtualBox 5.1.20 r114628 (Qt5.6.2)
  • Docker version 17.05.0-ce, build 89658be
  • docker-machine.exe version 0.11.0, build 5b27455

  • 튜토리얼


  • Part 1: Orientation and Setup

  • Part 2: Containers
  • 【Docker】공식 튜토리얼을 해 보았다 【Part1/Part2】


  • Part 3: Services
  • 【Docker】공식 튜토리얼을 해 보았다 【Part3】


  • Part 4: Swarms
  • 【Docker】공식 튜토리얼을 해 보았다 【Part4】

  • Part 5: Stacks
  • Part 6: Deploy your app

  • Part 4: Swarms



    클러스터 만들기


  • VirtualBox 드라이버를 사용하여 두 개의 VM을 만듭니다.
    $ docker-machine create --driver virtualbox myvm1
    $ docker-machine create --driver virtualbox myvm2
    

    이런 식으로 myvm1myvm2 가 작성되고 있다


  • 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.ymlmyvm1 에 복사
  • $ 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 stack을 파괴 할 수 있습니다.
    $ 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>"                                                                      
    

    좋은 웹페이지 즐겨찾기