docker - compose 명령 및 Yml 파일

6420 단어
Docker - compose 상용 명령
docker-compose up -d nginx                          nignx  

docker-compose exec nginx bash               nginx   

docker-compose down                                  nginx  ,  

docker-compose ps                                         

docker-compose restart nginx                       nginx  

docker-compose run --no-deps --rm php-fpm php -v   php-fpm        ,     php -v          

docker-compose build nginx                          。        

docker-compose build --no-cache nginx          。

docker-compose logs  nginx                       nginx    

docker-compose logs -f nginx                     nginx     

 

docker-compose config  -q                        (docker-compose.yml)    ,      ,       ,       ,      。 

docker-compose events --json nginx        json     nginx docker  

docker-compose pause nginx                   nignx  

docker-compose unpause nginx               ningx  

docker-compose rm nginx                           (         )

docker-compose stop nginx                      nignx  

docker-compose start nginx                      nignx  


docker-compose.ymal
홈 페이지 예제:
version: "3.7"
services:

  redis:
    image: redis:alpine
    ports:
      - "6379"
    networks:
      - frontend
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

  db:
    image: postgres:9.4
    volumes:
      - db-data:/var/lib/postgresql/data
    networks:
      - backend
    deploy:
      placement:
        constraints: [node.role == manager]

  vote:
    image: dockersamples/examplevotingapp_vote:before
    ports:
      - "5000:80"
    networks:
      - frontend
    depends_on:
      - redis
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
      restart_policy:
        condition: on-failure

  result:
    image: dockersamples/examplevotingapp_result:before
    ports:
      - "5001:80"
    networks:
      - backend
    depends_on:
      - db
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

  worker:
    image: dockersamples/examplevotingapp_worker
    networks:
      - frontend
      - backend
    deploy:
      mode: replicated
      replicas: 1
      labels: [APP=VOTING]
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
        window: 120s
      placement:
        constraints: [node.role == manager]

  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - "8080:8080"
    stop_grace_period: 1m30s
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      placement:
        constraints: [node.role == manager]

networks:
  frontend:
  backend:

volumes:
  db-data:

부분 분해
##           
services:
  web:
    image: hello-world


##    dockerfile 
build: /path/to/build/dir
build: ./dir
build:
  context: ../
  dockerfile: path/of/Dockerfile

build: ./dir
image: webapp:tag


##command 
command                  
command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000]

##container_name
Compose         :
           、    ,               ,          
container_name: app

##depends_on
depends_on        、       
version: '2'
services:
  web:
    build: .
    depends_on:
      - db
      - redis
  redis:
    image: redis
  db:


##dns
dns: 8.8.8.8
dns:
  - 8.8.8.8
  - 9.9.9.9

dns_search: example.com
dns_search:
  - dc1.example.com
  - dc2.example.com

##tmfs
           , run       
tmpfs: /run
tmpfs:
  - /run
  - /tmp

##environment
      ,           ,                   
environment:
  RACK_ENV: development
  SHOW: 'true'
  SESSION_SECRET:
 
environment:
  - RACK_ENV=development
  - SHOW=true
  - SESSION_SECRET
 
##expose
         ,        ,        ports  
expose:
 - "3000"
 - "8000"

##external_links
   Docker    ,          docker run     ,   Compose        docker-compose.yml      ,           ,  external_links,    Compose                     (                                    )
 
external_links:
 - redis_1
 - project_db_1:mysql
 - project_db_1:postgresql

##extra_hosts
        ,       /etc/hosts         
extra_hosts:
 - "somehost:162.242.195.82"
 - "otherhost:50.31.209.229"

##labels
        , Dockerfile lable      

labels:
  com.example.description: "Accounting webapp"
  com.example.department: "Finance"
  com.example.label-with-empty-value: ""
labels:
  - "com.example.description=Accounting webapp"
  - "com.example.department=Finance"
  - "com.example.label-with-empty-value"
 
##links
        , docker –link     ,            ,                /etc/hosts   
links:
 - db
 - db:database
 - redis


##ports
      
  HOST:CONTAINER             ,          
ports:
 - "3000"
 - "8000:8000"
 - "49100:22"
 - "127.0.0.1:8001:8001"
   HOST:CONTAINER        ,            60           ,  YAML    xx:yy       60  。           

##security_opt
            。               ,         user    USER
security_opt:
  - label:user:USER
  - label:role:ROLE

##volumes
                    ,      [HOST:CONTAINER]     ,    [HOST:CONTAINER:ro]     ,        ,       ,                。
compose               ,   .    …        
 
volumes:
  //         ,Docker            (          )。
  - /var/lib/mysql
 
  //            
  - /opt/data:/var/lib/mysql
 
  //   Compose                       。
  - ./cache:/tmp/cache
 
  //          (~/        /home//    /root/)。
  - ~/configs:/etc/configs/:ro
 
  //            。
  - datavolume:/var/lib/mysql
 
            ,       volume_driver。
volume_driver: mydriver

##volumes_from
              ,      :ro  :rw,        ,                ,        

volumes_from:
  - service_name
  - service_name:ro
  - container:container_name
  - container:container_name:rw

##network_mode
    , docker client –net    ,        service:[sevice name]   
network_mode: "bridge"
network_mode: "host"
network_mode: "none"
network_mode: "service:[service name]"
network_mode: "container:[container name/id]"
 
##networks
      
services:
  some-service:
    networks:
     - some-network
     - other-network

좋은 웹페이지 즐겨찾기