docker-编排文件(compose file)

运维 专栏收录该内容
22 篇文章 0 订阅

参考使用文档语法文档

安装方法(Linux)

//下载
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
//授权
sudo chmod +x /usr/local/bin/docker-compose
//软链接
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
//测试
docker-compose --version

常用命令

//忽略缓存,重新构建镜像
docker-compose --no-cache build image1 image2 ...
//【后台】构建镜像,启动容器
docker-compose up -d
//关掉容器,并删除容器
docker-compose down
//关掉容器,并删除容器和没有指定tag的镜像(一般指那些从dockerfile创建的镜像,有更新文件时,这个比较好用)
docker-compose down --rmi local

参考样例

version: "3.7"		#版本号		
networks:		#定义网络
  xxl:
    name: xxl		#网络名称
    driver: bridge		#网络驱动
    ipam:
      driver: default
      config:
        - subnet: 172.18.0.0/16		#子网ip
services:		#定义服务
  nginx:
    container_name: xxl-nginx		#容器名称
    image: nginx		#使用现有镜像
    networks:		#所在网络
      - xxl
    ports:		#端口映射
      - "0.0.0.0:80:80"
    volumes:		#文件映射
      - "./nginx/nginx.conf:/etc/nginx/nginx.conf:ro"
      - "./dist:/dist:ro"
    restart: always		#重启策略
    links:
      - peri		#关联的服务,关联之后本服务可以通过服务名访问其他服务
      - website		
  redis:
    container_name: xxl-redis
    image: redis
    networks:
      - xxl
    ports:
      - "0.0.0.0:6379:6379"
    volumes:
      - "./redis/redis.conf:/etc/redis/redis.conf:ro"
      - "./redis:/data:rw"
    command: redis-server /etc/redis/redis.conf		#覆盖默认的启动命令,这里是指定配置文件启动redis
    restart: always
  mysql:
    container_name: xxl-mysql
    image: mysql
    networks:
      - xxl
    ports:
      - "0.0.0.0:3306:3306"
    volumes:
      - "./mysql:/var/lib/mysql:rw"
    restart: always
  rabbitmq:
    container_name: xxl-rabbitmq
    build:		#使用dockerfile构建镜像
      context: .
      dockerfile: ./dockerfile/rabbitmq/Dockerfile
    networks:
      - xxl
    ports:
      - "0.0.0.0:15672:15672"
      - "0.0.0.0:1883:1883"
    restart: always
  nexus:
    container_name: xxl-nexus
    image: sonatype/nexus3
    networks:
      - xxl
    ports:
      - "0.0.0.0:8081:8081"
    volumes:
      - "./nexus:/nexus-data:rw"
    restart: always
  peri:
    container_name: xxl-peri
    build:
      context: D:\IdeaProjects\periscope-server\build\docker
      dockerfile: ./Dockerfile
    environment:
      - "SPRING_PROFILES_ACTIVE=peri"		#spring-boot程序可以通过这个环境变量指令激活的profile
    networks:
      - xxl
    volumes:
      - "./server/peri:/app/file:rw"
    restart: always
    links:
      - mysql
      - redis
      - rabbitmq
  website:
    container_name: xxl-website
    build:
      context: D:\IdeaProjects\periscope-server\build\docker
      dockerfile: ./Dockerfile
    environment:
      - "SPRING_PROFILES_ACTIVE=website"
    networks:
      - xxl
    volumes:
      - "./server/website:/app/file:rw"
    restart: always
    links:
      - mysql
      - redis
      - rabbitmq
  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值