docker springboot 运维部署详细实例

环境安装

plain 复制代码
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker -v
Docker version 26.1.4, build 5650f9b

镜像构建

Dockerfile 文件内容

plain 复制代码
FROM openjdk:8
# Author Info 创建人信息
MAINTAINER [email protected]
ENV PORT=20001
EXPOSE 20001
RUN mkdir /usr/local/ratel-boot-server
WORKDIR /usr/local/ratel-boot-server
# Rename Jar File To Container
COPY ratel-boot-server.jar ./ratel-boot-server.jar
# Run Config
ENTRYPOINT [ "java", "-java", "/ratel-boot-server.jar" ]

自己打包的 jar 包

plain 复制代码
-rw-r--r-- 1 root root      336 Dec 17 11:50 Dockerfile
-rwxrwxrwx 1 root root 65123176 Dec 13 17:59 ratel-boot-server.jar
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# ls
Dockerfile  ratel-boot-server.jar

根据 Dockerfile 构建镜像

plain 复制代码
docker build -t ratel-boot-server:v1.0.0 .

[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker build -t ratel-boot-server:v1.0.0 .
[+] Building 0.2s (9/9) FINISHED                                                                               docker:default
 => [internal] load build definition from Dockerfile                                                                     0.0s
 => => transferring dockerfile: 375B                                                                                     0.0s
 => [internal] load metadata for docker.io/library/openjdk:8                                                             0.0s
 => [internal] load .dockerignore                                                                                        0.0s
 => => transferring context: 2B                                                                                          0.0s
 => [1/4] FROM docker.io/library/openjdk:8                                                                               0.0s
 => [internal] load build context                                                                                        0.0s
 => => transferring context: 45B                                                                                         0.0s
 => CACHED [2/4] RUN mkdir /usr/local/ratel-boot-server                                                                  0.0s
 => CACHED [3/4] WORKDIR /usr/local/ratel-boot-server                                                                    0.0s
 => CACHED [4/4] COPY ratel-boot-server.jar ./ratel-boot-server.jar                                                      0.0s
 => exporting to image                                                                                                   0.0s
 => => exporting layers                                                                                                  0.0s
 => => writing image sha256:eebdebddf3f72373b23a1f291609613eb88b237e07dc8d6fbba810decfc3b14d                             0.0s
 => => naming to docker.io/library/ratel-boot-server:v1.0.0                                                              0.0s

镜像运行

本地换或者开发环境 构建镜像

rbt1 和 rbt2 容器都起来来

plain 复制代码
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker run --name rbt1 -p 20001:20001 --privileged=true --restart=always -idt ratel-boot-server:v1.0.0
6c9ed23572951d9127416802a6f5c484860ca30aa3f7132f22fb1b4b74c55e42
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker run --name rbt2 -p 20002:20001 --privileged=true --restart=always -idt ratel-boot-server:v1.0.0
2a5b430255170b24da51fffc2e9345024de71094abf5d38ba55c3cc753774897
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker ps
CONTAINER ID   IMAGE                           COMMAND                  CREATED          STATUS                                  PORTS                                                           NAMES
2a5b43025517   ratel-boot-server:v1.0.0        "java -java /ratel-b..."   5 seconds ago    Restarting (1) Less than a second ago                                                                   rbt2
6c9ed2357295   ratel-boot-server:v1.0.0        "java -java /ratel-b..."   15 seconds ago   Restarting (1) 1 second ago                                                                             rbt1
71235a26e5c6   ubuntu:18.04                    "/bin/bash"              10 minutes ago   Up 9 minutes                                                                                            verdant_hirquiticke
23d594db7e77   ubuntu:18.04                    "/bin/bash"              55 minutes ago   Up 44 minutes                                                                                           verdant_grommet
ba4ca0dcfcc8   ubuntu:18.04                    "/bin/bash"              7 hours ago      Up 7 hours                                                                                              zealous_quire
22afff419daf   ubuntu:18.04                    "/bin/bash"              8 hours ago      Up 8 hours                                                                                              baleful_obelus
8d6f4a67a2f5   portainer/portainer-ce:latest   "/portainer"             25 hours ago     Up 8 hours                              8000/tcp, 9443/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp   portainer
[root@iZbp1dcnzq7pzpg9607m6pZ ~]#

镜像模板提交

提交镜像模板

plain 复制代码
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker commit rbt1 template/ratel-boot-server:v1.0.0
sha256:a0e438bda894e99e79840b867f3677add07162b1e89ca8d7ec6a1fc1efca7674
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker images
REPOSITORY                   TAG       IMAGE ID       CREATED         SIZE
template/ratel-boot-server   v1.0.0    a0e438bda894   6 seconds ago   591MB
ratel-boot-server            v1.0.0    eebdebddf3f7   7 hours ago     591MB
openjdk                      8         e24ac15e052e   2 years ago     526MB
portainer/portainer-ce       latest    0df02179156a   3 years ago     273MB
alpine                       latest    c059bfaa849c   3 years ago     5.58MB
ubuntu                       18.04     5a214d77f5d7   3 years ago     63.1MB
[root@iZbp1dcnzq7pzpg9607m6pZ ~]#

生成测试环境和生产环境镜像

plain 复制代码
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker tag ratel-boot-server:v1.0.0 testhabor/testapp:v1.0.0
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker tag ratel-boot-server:v1.0.0 prodhabor/prodapp:v1.0.0

ratel-boot-server v1.0.0 自己构建的

template/ratel-boot-server v1.0.0 提交的模板

testhabor/testapp v1.0.0 测试环境

prodhabor/prodapp v1.0.0 生产环境

plain 复制代码
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker images
REPOSITORY                   TAG       IMAGE ID       CREATED         SIZE
template/ratel-boot-server   v1.0.0    a0e438bda894   4 minutes ago   591MB
ratel-boot-server            v1.0.0    eebdebddf3f7   7 hours ago     591MB
prodhabor/prodapp            v1.0.0    eebdebddf3f7   7 hours ago     591MB
testhabor/testapp            v1.0.0    eebdebddf3f7   7 hours ago     591MB
openjdk                      8         e24ac15e052e   2 years ago     526MB
portainer/portainer-ce       latest    0df02179156a   3 years ago     273MB
alpine                       latest    c059bfaa849c   3 years ago     5.58MB
ubuntu                       18.04     5a214d77f5d7   3 years ago     63.1MB

镜像模板 tag_ 推送测试环境 habor

:::color1

docker login 测试环境 habor

docker push testhaborr/ratel-boot-server:v1.0.0

:::

镜像模板 tag_ 推送生产环境 habor

镜像导出

:::color1

docker save -o ratelserver.tar ratel-boot-server:v1.0.0

:::

ratelserver.tar

plain 复制代码
REPOSITORY                   TAG       IMAGE ID       CREATED         SIZE
template/ratel-boot-server   v1.0.0    a0e438bda894   9 minutes ago   591MB
ratel-boot-server            v1.0.0    eebdebddf3f7   7 hours ago     591MB
prodhabor/prodapp            v1.0.0    eebdebddf3f7   7 hours ago     591MB
testhabor/testapp            v1.0.0    eebdebddf3f7   7 hours ago     591MB
openjdk                      8         e24ac15e052e   2 years ago     526MB
portainer/portainer-ce       latest    0df02179156a   3 years ago     273MB
alpine                       latest    c059bfaa849c   3 years ago     5.58MB
ubuntu                       18.04     5a214d77f5d7   3 years ago     63.1MB
[root@iZbp1dcnzq7pzpg9607m6pZ ~]# ls
Dockerfile  ratel-boot-server.jar  ratelserver.tar  sa_recovery.log
[root@iZbp1dcnzq7pzpg9607m6pZ ~]#
相关推荐
漫谈网络10 分钟前
基于 Netmiko 的网络设备自动化操作
运维·自动化·netdevops·netmiko
꧁坚持很酷꧂36 分钟前
Linux Ubuntu18.04下安装Qt Craeator 5.12.9(图文详解)
linux·运维·qt
时迁24738 分钟前
【k8s】k8s是怎么实现自动扩缩的
云原生·容器·kubernetes·k8s
小诸葛的博客2 小时前
详解Linux中的定时任务管理工具crond
linux·运维·chrome
一默19912 小时前
CentOS 7.9升级OpenSSH到9.9p2
linux·运维·centos
BranH3 小时前
Linux系统中命令设定临时IP
linux·运维·服务器
极小狐3 小时前
极狐GitLab 项目功能和权限解读
运维·git·安全·gitlab·极狐gitlab
宁酱醇3 小时前
GitLab_密钥生成(SSH-key)
运维·ssh·gitlab
秋风起,再归来~3 小时前
【Linux庖丁解牛】—进程优先级!
linux·运维·服务器
诡异森林。4 小时前
Docker--Docker网络原理
网络·docker·容器