环境安装

[root@iZbp1dcnzq7pzpg9607m6pZ ~]# docker -v
Docker version 26.1.4, build 5650f9b

镜像构建

Dockerfile 文件内容

FROM openjdk:8
# Author Info 创建人信息
MAINTAINER ratelcloud@foxmail.com
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 包

-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 构建镜像

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 容器都起来来

[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 ~]#

镜像模板提交

提交镜像模板

[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 ~]#

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

[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 生产环境

[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

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 ~]#