Jar包docker部署

Jar包docker部署

首先我们得有一个jar包,自己打包就行了

maven配置里面必须写上再打包才行

1
2
3
4
5
6
7
8
<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>
1
2
3
4
5
# 仅跳过测试执行(仍编译测试代码)
mvn clean package -DskipTests

# 彻底跳过测试(不编译、不执行测试代码,速度更快)
mvn clean package -Dmaven.test.skip=true

然后我们得编写Dockerfile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 设置环境
FROM openjdk:11.0-jre-buster
# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 复制jar包到容器中
COPY sentinel-dashboard.jar /sentinel-dashboard.jar
# 指定端口号
EXPOSE 8090
# 启动
ENTRYPOINT ["java", "-jar", "/sentinel-dashboard.jar", "--server.port=8090"]

创建容器

1
docker build -t sentinel:8090 .
参数 作用
-t 镜像名称
sentinel 镜像名称
8090 镜像端口
. Dockerfile所在目录

最后我们运行

1
2
3
4
5
docker run -d \  
    -p 8090:8090 \
    --name sentinel \
    --network shuimo \
    sentinel:8090
参数 作用
-d 后台运行
-p 端口映射
8090:8090 宿主机端口:容器端口
–name 容器名称
–network 网络名称
sentinel:8090 镜像名称:镜像端口
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计