安裝的話之前有說過,查看是否安裝docker-compose:
docker-compose -v
這里將下docker-compose.yml的配置
與Dockerfile類似兩者內容都有一些強制的要求 docker-compose.yml第一行必須指定version 關鍵字 可以設置為 version: '2' 也可以設置為version:‘3’ 區別:docker-compose文件使用哪個version的file格式 其他沒有 既然有version3了那就用version3唄。
然后是services:復數形式表名可配置多個service
如:
version: "3" 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]
emmm 參數的話英文名已經很明顯了,不做贅述。
啟動一個docker-compose:
在docker-compose.yml文件目錄下
docker-compose up
關閉:
docker-compose down
刪除docker rmi 刪除指定鏡像
查看docker-compose 命令幫助:
docker-compose help
docker-compose ps 查看所有容器 -q 值列出id
push 如果有搭建自己的docker服務器的話可以上傳到私服上
