Docker 服务编排 快速部署 SpringCloud 项目 (一)
一、docker-compose.yml
version: "3.3"
networks:
  zeal:
volumes:
  data:
services:
  gateway:
    restart: always
    build:
      context: ./gateway
      dockerfile: Dockerfile
    container_name: zeal_gateway #指定容器名称
    ports:
      - "8222:8222"
    networks:
      - zeal
  zeal_acl:
    build:
      context: ./zeal_acl
      dockerfile: Dockerfile
    container_name: zeal_acl #指定容器名称
    ports:
      - "8009:8009"
    networks:
      - zeal
  nacos:
    restart: always
    image: nacos/nacos-server:latest
    ports:
      - "8848:8848"
    environment:
      - "MODE=standalone"
    networks:
      - zeal
  mysql:
    restart: always
    image: daocloud.io/library/mysql:5.6.20 #指定镜像路径
    container_name: mysql #指定容器名称
    ports:
      - "3306:3306" #只写一个端口随机使用宿主机一个端口进行容器端口映射
    environment:
      - "MYSQL_ROOT_PASSWORD=root"
      - "TZ=Asia/Shanghai"
      - "MYSQL_DATABASE=zeal_acl"
    volumes:
        - /apps/conf/mysql:/var/lib/mysql #映射数据卷
        - /apps/db/zeal_acl/zeal_acl_db.sql:/docker-entrypoint-initdb.d/zeal_acl_db.sql
    networks:
      - zeal
  sentinel1:
    restart: always
    image: redis
    container_name: redis-sentinel-1
    command: redis-sentinel /apps/conf/redis/conf/sentinel1.conf # 自定义路径,可更改,但是需要和volumes中的路径相同。
    restart: always
    ports:
      - 26380:26380
    volumes:
      - ./apps/conf/redis/conf/sentinel1.conf:/apps/conf/redis/conf/sentinel1.conf # 自定义路径,可更改,但是需要和command中的路径相同。
    networks:
      - zeal
  sentinel2:
    restart: always
    image: redis
    container_name: redis-sentinel-2
    command: redis-sentinel /apps/conf/redis/conf/sentine2.conf
    restart: always
    ports:
      - 26381:26381
    volumes:
      - ./apps/conf/redis/conf/sentinel2.conf:/apps/conf/redis/conf/sentine2.conf
    networks:
      - zeal
  sentinel3:
    restart: always
    image: redis
    container_name: redis-sentinel-3
    command: redis-sentinel /apps/conf/redis/conf/sentine3.conf
    restart: always
    ports:
      - 26382:26382
    volumes:
      - ./apps/conf/redis/conf/sentinel3.conf:/apps/conf/redis/conf/sentine3.conf
    networks:
      - zeal
二、Dockerfile
FROM openjdk:8 ENV APP_HOME=/apps WORKDIR $APP_HOME COPY api_gateway-1.0-SNAPSHOT.jar api_gateway.jar EXPOSE 8222 ENTRYPOINT ["java","-jar"] CMD ["api_gateway.jar"]
三、部署注册中心 配置中心 Nacos
docker-compose up -d nacos


四、部署网关 Gateway
docker-compose up -d gateway

 
成功注册
五、部署MySql
docker-compose up -d mysql


六、部署Redis 哨兵模式
docker-compose up -d sentinel1 docker-compose up -d sentinel2 docker-compose up -d sentinel3

七、部署业务服务
docker-compose up -d zeal_acl



SUCCESS!!!!!
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号