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

소개


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

    환경


  • VirtualBox 5.1.22 r115126
  • 포트 포워딩 설정에서 액세스 할 수 있습니다.

  • Ubuntu16.04.2 LTS
  • Docker version 17.03.1-ce, build c6d412e
  • Docker 설치는 공식 절차에 따라 수행됩니다


  • 튜토리얼


  • 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 3: Services



    docker-compose.yml 만들기


  • 참고 정보: Compose file version 3 reference

  • docker-compose.yml
    version: "3"
    services:
      web:
        # Part2で作成したdocker cloudのイメージを使用
        image: tocyuki/repository:tag
        deploy:
          # 5台作成する
          replicas: 5
          resources:
            limits:
              # 最大10%までのCPU利用
              cpus: "0.1"
              # 最大50MBまでのメモリ利用
              memory: 50M
          restart_policy:
            condition: on-failure
        ports:
          # ホストの80番ポートをコンテナの80番ポートへマッピング
          - "80:80"
        networks:
          - webnet
    networks:
      webnet:
    

    docker swarm init 구현


  • 이 명령을 실행하면 실행 된 호스트를 docker swarm의 관리자 호스트로 만들 수 있습니다.
    tocyuki@vm01:~/docker_tutorial/part3$ docker swarm init
    Swarm initialized: current node (mfb7mslrjr6qbkkzi42x9525p) is now a manager.
    
    To add a worker to this swarm, run the following command:
    
        docker swarm join \
        --token SWMTKN-1-3562frmookuker51re8lelyaewh1c37g690yodforc13gxhby6-3gntbpftwe8br3h225i5ew7ul \
        10.0.2.15:2377
    
    To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
    

    앱 실행



  • getstartedlab이라는 이름으로 swarm 모드로 앱을 실행합니다.
    tocyuki@vm01:~/docker_tutorial/part3$ docker stack deploy -c docker-compose.yml getstartedlab
    Creating network getstartedlab_webnet
    Creating service getstartedlab_web
    

    컨테이너 시작 확인



    명령줄에서 확인


    tocyuki@vm01:~/docker_tutorial/part3$ docker stack ps getstartedlab
    ID            NAME                 IMAGE                   NODE  DESIRED STATE  CURRENT STATE          ERROR  PORTS
    msazmhxdrs9z  getstartedlab_web.1  tocyuki/repository:tag  vm01  Running        Running 4 seconds ago
    4bz3usxe0fpa  getstartedlab_web.2  tocyuki/repository:tag  vm01  Running        Running 4 seconds ago
    js4j0zhxaydu  getstartedlab_web.3  tocyuki/repository:tag  vm01  Running        Running 5 seconds ago
    5rdhkuc5xkns  getstartedlab_web.4  tocyuki/repository:tag  vm01  Running        Running 4 seconds ago
    p3tqe5lhu9zg  getstartedlab_web.5  tocyuki/repository:tag  vm01  Running        Running 4 seconds ago
    
    tocyuki@vm01:~/docker_tutorial/part3$ docker ps
    CONTAINER ID        IMAGE                                                                                        COMMAND             CREATED             STATUS              PORTS               NAMES
    49ffec8732f5        tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8   "python app.py"     3 minutes ago       Up 3 minutes        80/tcp              getstartedlab_web.4.5rdhkuc5xknsyeru01160pang
    7f105ebe27ed        tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8   "python app.py"     3 minutes ago       Up 3 minutes        80/tcp              getstartedlab_web.5.p3tqe5lhu9zgh1atrwe7svk59
    485d12957ac6        tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8   "python app.py"     3 minutes ago       Up 3 minutes        80/tcp              getstartedlab_web.1.msazmhxdrs9z75379ojwkgmgj
    a55408bffb42        tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8   "python app.py"     3 minutes ago       Up 3 minutes        80/tcp              getstartedlab_web.3.js4j0zhxaydun9wwv9xqtew5c
    c2d0e23af466        tocyuki/repository@sha256:1ae82dcb5528f752c9c1fc57a55ec0dde097ee2b119011ed2d99b3b9e81228d8   "python app.py"     3 minutes ago       Up 3 minutes        80/tcp              getstartedlab_web.2.4bz3usxe0fpaxsy0q9qi3ai53
    

    WEB 브라우저에서 확인


  • 업데이트하면 각 컨테이너에 부하가 분산되어 있음을 알 수 있습니다.







    앱 종료


    tocyuki@vm01:~/docker_tutorial/part3$ docker stack rm getstartedlab
    Removing service getstartedlab_web
    Removing network getstartedlab_webnet
    

    Part3에서 배운 명령의 치트 시트


    # List all running applications on this Docker host
    docker stack ls      
    
    # Run the specified Compose file        
    docker stack deploy -c <composefile> <appname>  
    
    # List the services associated with an app
    docker stack services <appname>    
    
    # List the running containers associated with an app   
    docker stack ps <appname>   
    
    # Tear down an application
    docker stack rm <appname>                             
    
  • 좋은 웹페이지 즐겨찾기