1,window安装docker工具,安装git工具
docker下载地址:docker.com
安装完成后启动docker,设置镜像源
{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": true,
"features": {
"buildkit": true
},
"log-driver": "json-file",
"log-opts": {
"max-file": "3",
"max-size": "400m"
},
"registry-mirrors": [
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://ccr.ccs.tencentyun.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.ustc.edu.cn"
]
}
git下载地址:Git for Windows
2,dockerfile镜像制作
准备一个腾讯DevOps_DevOps 解决方案_一站式 DevOps_开发者工具 | 腾讯云 CODING DevOps
注册后新建一个docker制品仓库(待会我们把制作的dockerfile镜像放到私有云这里)
idea项目跟目录下编写dev-.sh脚本
dev-buildAndPublishAmd64.sh内容如下:(这里需要安装maven)
#!/bin/bash
cd $(dirname $0)
#
#if [ $# -ne 1 ]; then
# echo "usage: buildAndPublish.sh version"
# exit 1
#fi
#
## 版本号
#version=$1
#echo "Build Version: $version"
mvn clean
mvn install
# docker build
#buildDist="chuxin-sdk:$version"
buildDist="mall-dev:dev20241204154801"
docker buildx build --platform=linux/amd64 -t ${buildDist} -f DockerfileDev .
docker tag ${buildDist} https://zvsz808-docker.pkg.coding.net/geewer/mall/${buildDist}
docker push https://zvsz808-docker.pkg.coding.net/geewer/mall/${buildDist}
编写DockerfileDev文件
FROM amazoncorretto:8
# Add your JAR files
ADD ./mall-api/target/mall-api-1.0-SNAPSHOT.jar mall-api-1.0-SNAPSHOT.jar
# 设置UTF-8编码环境变量
ENV LANG C.UTF-8
ENV LANGUAGE C
ENV LC_ALL C.UTF-8
WORKDIR /home
# Copy scripts and create directoriesRUN mkdir /home/data \
&& mkdir -p /data/log
# Set the locale to C.UTF-8 at the end of your Dockerfile if needed
ENV LANG C.UTF-8
上面2个shell的意思:maven编译打包后将mall-api.jar加入镜像中,安装亚马逊jdk8(个人喜欢amazoncorretto:8,openjdk8镜像会出现幺蛾子项目上的jdk问题),最后pull到https://zvsz808-docker.pkg.coding.net/geewer/mall目录下面
使用git bash执行
3.linux下拉取镜像
docker登陆,修改自己的账号密码
docker login -u test@qq.com -p 123456 /zvsz808-docker.pkg.coding.net
镜像拉取(主节点服务和从节点服务都要拉取镜像)
docker pull zvsz808-docker.pkg.coding.net/geewer/mall:dev20241204154801
也可以查看coding操作指引
4,启动项目
安装部署docker swarm查看作者:ubuntu docker swarm部署一个集群-CSDN博客
查看服务节点
docker node ls
假设节点为node01,node02,设置节点添加标签
docker node update --label-add mall-api=true node01
docker node update --label-add mall-api=true node02
查看节点标签策略
docker node inspect node01 --pretty
编写一个docker-compose.yml文件
replicas: 2 #运行2个节点
placement:
constraints:
- node.labels.mall-api == true #标签
上面代码运行2个副本,每个节点一个副本mall-api
version: '3.2'
services:
mall-api:
image: zvsz808-docker.pkg.coding.net/geewer/mall/mall-api:dev20241204154801
#container_name: mall-api
networks:
- xbiz
- xdb
ports:
- 8080:8080
volumes:
- type: bind
source: "/data/app/api/logs"
target: "/data/mall"
command: sh -c "java -Xmx2048m -Xms2048m -Duser.timezone=GMT+08 -Dfile.encoding=UTF-8 -Dspring.profiles.active=docker -jar /mall-api-1.0-SNAPSHOT.jar"
deploy:
mode: replicated
replicas: 2 #运行2个节点
placement:
constraints:
- node.labels.mall-api == true #标签
networks:
xbiz:
external:
name: "swarm_xbiz"
xdb:
external:
name: "swarm_xdb"
创建环境网络
docker network create -d overlay swarm_xdb
docker network create -d overlay swarm_xbiz
查看当前的网络
docker network ls
启动mall-api.jar项目
docker stack deploy -c <(docker-compose -f docker-compose.yml config) mall-api
查看所有服务
docker service ls
查看日志
docker service ls
docker service ps --no-trunc v7c8oxsy3j9r
标签:java,coding,swram,mall,api,https,ubuntu,镜像,docker
From: https://blog.csdn.net/qq_30333355/article/details/144239377