docker-compose部署nacos单机版(简洁优化版)

预览

nacos
dashboard

初始化数据库

MySQL 文件:
https://github.com/Gleans/SpringCloudPro/blob/master/docker/mysql-init/init.sql

放到可视化工具或者命令行执行以下,目的是 初始化数据库
初始化数据库

docker-compose 启动 nacos 单机版

docker-compose.yml

# 启动命令
# docker-compose --compatibility up -d
version: '3'

services:
  mysql5.7:
    image: mysql:5.7
    container_name: mysql57
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: nacos
      MYSQL_USER: root
      MYSQL_PASSWORD: root
    ports:
      - 3306:3306
    volumes: # 挂载持久化地址(个人理解)
      - ./docker/mysql/:/var/lib/mysql/
      - ./docker/conf/:/etc/mysql/
  nacos:
    image: nacos/nacos-server:1.2.1
    container_name: nacos
    restart: always
    depends_on:
      - mysql5.7
    environment:
      PREFER_HOST_MODE: hostname #如果支持主机名可以使用hostname,否则使用ip,默认也是ip
      SPRING_DATASOURCE_PLATFORM: mysql #数据源平台 仅支持mysql或不保存empty
      MODE: standalone
      MYSQL_SERVICE_HOST: mysql5.7
      MYSQL_SERVICE_DB_NAME: nacos
      MYSQL_SERVICE_PORT: 3306
      MYSQL_SERVICE_USER: root
      MYSQL_SERVICE_PASSWORD: root
      NACOS_APPLICATION_PORT: 9999
      JVM_XMS: 512m
      JVM_MMS: 320m
    volumes:
      - ./docker/nacos/standalone-logs/:/home/nacos/logs
      - ./docker/nacos/plugins/:/home/nacos/plugins
      - ./docker/nacos/conf/application.properties:/home/nacos/conf/application.properties
    ports:
      - "9999:9999"
  prometheus:
    container_name: prometheus
    image: prom/prometheus:latest
    volumes:
      - ./docker/nacos/prometheus/prometheus-standalone.yaml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"
    depends_on:
      - nacos
    restart: on-failure
  grafana:
    container_name: grafana
    image: grafana/grafana:latest
    ports:
      - 3000:3000
    restart: on-failure

上面挂载的文件以及 volumes 都在 Github
配置已经在 Windows 以及 Mac_OS 实测通过的
地址:https://github.com/Gleans/SpringCloudPro/tree/master/docker

启动

docker-compose --compatibility up -d

打印日志,我这里是已经启动过了

D:\workspaces\SpringCloudPro>docker-compose --compatibility up -d
mysql57 is up-to-date
grafana is up-to-date
Recreating rabbitmq ...
redis is up-to-date
nacos is up-to-date
Recreating rabbitmq ... done

up-to-date 代表你可以修改一些配置然后运行docker-compose --compatibility up -d命令,它只会更新重启你修改的容器,就很人性化

访问web

地址:http://127.0.0.1:9999/nacos/#/login
nacos-web
默认帐户与登录密码:

  • 账号:nacos
  • 密码:nacos

到此,docker-compose启动nacos单机版完成

posted @ 2020-07-25 09:06  JavaPro  阅读(15315)  评论(1编辑  收藏  举报
豫ICP备19010929号