Apollo——docker-compose运行Apollo

2024-08-16 14:59:09 浏览数 (2)

前言

本地开发需要Apollo,记录下写的docker-compose的脚本

  • 官方文档: https://www.apolloconfig.com/
  • SERVER_SERVLET_CONTEXT_PATH: Portal挂载到nginx/slb后如何设置相对路径
  • apolloportaldb.sql: https://github.com/apolloconfig/apollo/blob/master/scripts/sql/apolloportaldb.sql
  • apolloconfigdb.sql: https://github.com/apolloconfig/apollo/blob/master/scripts/sql/apolloconfigdb.sql
  • 默认登录账号/密码: apollo/admin

内容

目录结构

代码语言:javascript复制
apollo/
├── docker-compose.yml
└── sql
    ├── apolloconfigdb.sql
    └── apolloportaldb.sql

docker-compose.yml

192.168.223.10为本地虚机内网IP

代码语言:javascript复制
version: '3'
services:
  apollo-configservice:
    image: apolloconfig/apollo-configservice:latest
    container_name: apollo-configservice
    restart: always
    ports:
      - "8080:8080"
    volumes:
      - /tmp/logs:/opt/logs
    environment:
      SERVER_PORT: 8080
      EUREKA_INSTANCE_IP_ADDRESS: 192.168.223.10
      EUREKA_INSTANCE_HOME_PAGE_URL: "http://192.168.223.10:8080"
      EUREKA_INSTANCE_PREFER_IP_ADDRESS: false
      SPRING_DATASOURCE_URL: 'jdbc:mysql://192.168.223.10:13306/ApolloConfigDB?characterEncoding=utf8'
      SPRING_DATASOURCE_USERNAME: 'root'
      SPRING_DATASOURCE_PASSWORD: '123456'
    depends_on:
      - apollo-db

  apollo-adminservice:
    image: apolloconfig/apollo-adminservice:latest
    container_name: apollo-adminservice
    restart: always
    ports:
      - "8090:8090"
    volumes:
      - /tmp/logs:/opt/logs
    environment:
      SERVER_PORT: 8090
      EUREKA_INSTANCE_IP_ADDRESS: 192.168.223.10
      EUREKA_INSTANCE_HOME_PAGE_URL: "http://192.168.223.10:8090"
      EUREKA_INSTANCE_PREFER_IP_ADDRESS: false
      SPRING_DATASOURCE_URL: 'jdbc:mysql://192.168.223.10:13306/ApolloConfigDB?characterEncoding=utf8'
      SPRING_DATASOURCE_USERNAME: 'root'
      SPRING_DATASOURCE_PASSWORD: '123456'
    depends_on:
      - apollo-configservice

  apollo-db:
    image: mysql:5.7
    container_name: apollo-db
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: 123456
    depends_on:

      - apollo-dbdata
    ports:
      - "13306:3306"
    volumes:
      - ./sql:/docker-entrypoint-initdb.d
    volumes_from:
      - apollo-dbdata

  apollo-dbdata:
    image: alpine:latest
    container_name: apollo-dbdata
    volumes:
      - /var/lib/mysql


  apollo-portal:
    image: apolloconfig/apollo-portal:latest
    container_name: apollo-portal
    restart: always
    ports:
      - "8070:8070"
    volumes:
      - /tmp/logs:/opt/logs
    environment:
      DS_URL: "jdbc:mysql://192.168.223.10:13306/ApolloPortalDB?characterEncoding=utf8"
      DS_USERNAME: "root"
      DS_PASSWORD: "123456"
      APOLLO_PORTAL_ENVS: "DEV"
      DEV_META: "http://192.168.223.10:8080"
      #SERVER_SERVLET_CONTEXT_PATH: "/apollo"
    depends_on:
      - apollo-adminservice

配置eureka.service.url

  • 将eureka.service.url修改成自己的虚机地址
  • 修改后apollo-configservice会从DB中读取

查看服务

浏览器访问192.168.223.10:8070

0 人点赞