1、项目地址
https://gitee.com/hhll/blog-hangliang.git
2、打包docker镜像并上传docker hub
【1】注册docker hub账号https://hub.docker.com/
【2】在docker hub建对应的仓库
【3】登录docker hub并打包上传前后端镜像
sudo docker login -u xxxx 密码 xxxxxx
后端:先将jar包替换
docker build -t="blgserver" .
sudo docker tag blgserver huanl250/myblog-server:1.2
sudo docker push huanl250/myblog-server:1.2
前端:先将dist替换
docker build -t="blgfront" .
sudo docker tag blgfront huanl250/myblog-front:1.0
sudo docker push huanl250/myblog-front:1.0
sudo docker pull huanl250/myblog-front:1.0
本地docker目录结构
3、腾讯云服务器配置
【1】购买服务器,装带docker的ubuntu系统
【2】登录系统检查环境
【3】编写docker compose文件
version: '3'
services:
front:
image: huanl250/myblog-front:latest
restart: "always"
privileged: true
container_name: compose-frontapp
ports:
- "8080:80"
web:
image: serverapp:latest
restart: "always"
privileged: true
container_name: compose-serverapp
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/my_blog?serverTimezone=GMT%2B8&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&rewriteBatchedStatements=true
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: xxxxx
SPRING_PROFILES_ACTIVE: test
MINIO_ENDPOINT: http://43.143.89.220:9000
MINIO_SAVEFILEPATH: /home/temp1/
MINIO_unZipFilePath: /home/temp/
MINIO_PASSWORD: root123456
MINIO_USERNAME: root
MINIO_BUCKET: test
ports:
- "38080:8080"
links:
- mysql
- minio
depends_on:
- mysql
- minio
mysql:
image: mysql
restart: "always"
privileged: true
container_name: compose-mysql
ports:
- "33306:3306"
environment:
MYSQL_ROOT_PASSWORD: xxxxx
volumes:
- /home/huangliang/mysql/data:/var/lib/mysql
- /home/huangliang/mysql/config:/etc/mysql/conf.d
- /home/huangliang/mysql/logs:/var/log/mysql
minio:
image: minio/minio
restart: "always"
privileged: true
container_name: compose-minio
ports:
- "9000:9000"
- "9001:9001"
volumes:
- /home/huangliang/minio/data:/data
environment:
MINIO_ROOT_USER: root
MINIO_ROOT_PASSWORD: xxxxx
command: server /data --console-address ":9001"
【4】启动服务
sudo docker-compose down
sudo docker-compose up -d
如果是用同一个版本号需要先docker pull