rap2 docker容器部署,前后端docker部署
官方提供了docker-compose安装步骤,本以为一键搞定,结果服务器上docker-compse与docker版本冲突,搞不定啊搞不定,无奈只能手动建容器部署了
参考docker-compse配置文件
# [email protected]
# [email protected]
# [email protected]
version: "3"
services:
# frontend
dolores:
image: rapteam/rap2-dolores:latest
ports:
#冒号前可以自定义前端端口号,冒号后不要动
- 3000:38081
# backend
delos:
image: rapteam/rap2-delos:latest
ports:
# 这里的配置不要改哦
- 38080:38080
environment:
- SERVE_PORT=38080
# if you have your own mysql, config it here, and disable the 'mysql' config blow
- MYSQL_URL=mysql8 # links will maintain /etc/hosts, just use 'container_name'
- MYSQL_PORT=3306
- MYSQL_USERNAME=root
- MYSQL_PASSWD=xxxxxxx
- MYSQL_SCHEMA=rap2
# redis config
- REDIS_URL=xxx.xxx.xxx.xxx
- REDIS_PORT=6379
- REDIS_PWD=xxxx
# production / development
- NODE_ENV=production
###### 'sleep 30 && node scripts/init' will drop the tables
###### RUN ONLY ONCE THEN REMOVE 'sleep 30 && node scripts/init'
command: /bin/sh -c 'node dispatch.js'
# init the databases
# command: sleep 30 && node scripts/init && node dispatch.js
# without init
# command: node dispatch.js
:
- redis
- mysql8
部署后端node服务的docker容器,
镜像名称 rapteam/rap2-delos:latest
新建数据库配置
CREATE DATABASE rap2 CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE USER rapuser IDENTIFIED BY 'xxxxx';
GRANT ALL ON rap2.* to 'rapuser'@'%' ;
新建容器
docker run -p 38080:38080 \
--restart always \
--name rap2-delos \
# 配置服务端口
-e SERVE_PORT=38080 \
# 配置数据库mysql
-e MYSQL_URL=172.28.112.xxx \
-e MYSQL_PORT=3306 \
-e MYSQL_USERNAME=rapuser \
-e MYSQL_PASSWD=xxxxx \
-e MYSQL_SCHEMA=rap2 \
# 配置redis缓存服务
-e REDIS_URL=172.28.112.xxx \
-e REDIS_PORT=6379 \
-e REDIS_PWD=xxxx\
# 环境版本
-e NODE_ENV=production \
-d rapteam/rap2-delos:latest \
# 服务启动命令
node dispatch.js
启动成功后 初始化数据库
docker exec -it rap2-delos /bin/sh -c 'node scripts/init'
重启容器
docker restart rap2-delos
部署前端nodejs框架服务,
镜像 rapteam/rap2-dolores:latest
docker run -p 3000:38081 \
--restart always \
--name rap2-dolores \
-e SERVE_PORT=38080 \
-d rapteam/rap2-dolores:latest
curl http://localhost:3000
前端页面端口3000 服务api端口38080
参考官方文档地址
https://hub.docker.com/r/rapteam/rap2-delos
https://hub.docker.com/r/rapteam/rap2-dolores
https://github.com/thx/rap2-delos