docker-compose的使用

  安装的话之前有说过,查看是否安装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服务器的话可以上传到私服上

posted @ 2019-05-19 15:17  落楝花  阅读(3906)  评论(0编辑  收藏  举报

乘兴而来