Skip to main content
版本:2.5.0

Docker部署

本文介绍使用 docker 来部署 Apache ShenYu 网关。

在阅读本文档前,你需要先阅读部署先决条件文档来完成部署 shenyu 前的环境准备工作。

启动Apache ShenYu Admin

docker pull apache/shenyu-admin:${current.version}
docker network create shenyu
  • 使用 h2 来存储后台数据:
docker run -d -p 9095:9095 \
--net shenyu apache/shenyu-admin:${current.version}
docker run -v /${your_work_dir}/ext-lib:/opt/shenyu-admin/ext-lib \
-e "SPRING_PROFILES_ACTIVE=mysql" \
-e "spring.datasource.url=jdbc:mysql://${your_ip_port}/shenyu?useUnicode=true&characterEncoding=utf8 \
&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull" \
-e "spring.datasource.username=${your_username}" \
-e "spring.datasource.password=${your_password}" \
-d -p 9095:9095 --net shenyu apache/shenyu-admin:${current.version}

另外一种方式, 从 配置文件地址 中把 application.ymlapplication-mysql.yml配置放到${your_work_dir}/conf , 调整application.yml中的配置spring.profiles.active = mysql,然后执行以下语句:

docker run -v ${your_work_dir}/conf:/opt/shenyu-admin/conf \
-v /${your_work_dir}/ext-lib:/opt/shenyu-admin/ext-lib \
-d -p 9095:9095 --net shenyu apache/shenyu-admin:${current.version}
  • 使用 PostgreSql 来存储后台数据, 按照 指引文档 初始化数据库, 执行以下语句:
docker run -e "SPRING_PROFILES_ACTIVE=pg" \
-e "spring.datasource.url=jdbc:postgresql://${your_ip_port}/shenyu?useUnicode=true&characterEncoding=utf-8&useSSL=false" \
-e "spring.datasource.username=${your_username}" \
-e "spring.datasource.password=${your_password}" \
-d -p 9095:9095 --net shenyu apache/shenyu-admin:${current.version}

另外一种方式, 从 配置文件地址 中把 application.ymlapplication-pg.yml配置放到${your_work_dir}/conf, 调整application.yml中的配置spring.profiles.active = pg,然后执行以下语句:

docker run -v ${your_work_dir}/conf:/opt/shenyu-admin/conf \
-d -p 9095:9095 --net shenyu apache/shenyu-admin:${current.version}
  • 使用 Oracle 来存储后台数据, 按照 指引文档 初始化数据库, 执行以下语句:
docker run -e "SPRING_PROFILES_ACTIVE=oracle" \
-e "spring.datasource.url=jdbc:oracle:thin:@localhost:1521/shenyu" \
-e "spring.datasource.username=${your_username}" \
-e "spring.datasource.password=${your_password}" \
-d -p 9095:9095 --net shenyu apache/shenyu-admin:${current.version}

另外一种方式, 从 配置文件地址 中把 application.ymlapplication-oracle.yml 配置放到${your_work_dir}/conf, 调整application.yml中的配置spring.profiles.active = oracle,然后执行以下语句:

docker run -v ${your_work_dir}/conf:/opt/shenyu-admin/conf \
-d -p 9095:9095 --net shenyu apache/shenyu-admin:${current.version}

启动Apache ShenYu Bootstrap

宿主机中,bootstrap的配置文件所在目录记为 $BOOTSTRAP_CONF

docker run -d \
-p 9195:9195 \
-v $BOOTSTRAP_CONF:/opt/shenyu-bootstrap/conf \
--name shenyu-bootstrap \
--net shenyu \
--env SHENYU_SYNC_WEBSOCKET_URLS=ws://shenyu-admin:9095/websocket \
apache/shenyu-bootstrap:${current.version}