springboot项目打包成镜像并安装vi

 

1.Dockerfile文件内容:

[root@localhost myspringboot]# more Dockerfile 
FROM java:21.0.4-9
RUN apt-get update && apt-get install -y vim

COPY *.jar /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
####springboot项目配置的端口
EXPOSE 8888

 

2.构建

[root@localhost myspringboot]# docker build -t myspringboot_new .
[+] Building 539.5s (8/8) FINISHED                                                                                    docker:default
 => [internal] load build definition from Dockerfile                                                                            0.1s
 => => transferring dockerfile: 212B                                                                                            0.0s
 => [internal] load metadata for docker.io/library/java:21.0.4-9                                                                0.0s
 => [internal] load .dockerignore                                                                                               0.1s
 => => transferring context: 2B                                                                                                 0.0s
 => CACHED [1/3] FROM docker.io/library/java:21.0.4-9                                                                           0.0s
 => [internal] load build context                                                                                               0.3s
 => => transferring context: 58B                                                                                                0.0s
 => [2/3] RUN apt-get update && apt-get install -y vim                                                                        532.9s
 => [3/3] COPY *.jar /app.jar                                                                                                   1.5s 
 => exporting to image                                                                                                          2.5s 
 => => exporting layers                                                                                                         1.8s 
 => => writing image sha256:1f5add40b9d14286a32f05f00fdddf428cfbd7137242302728a03fca3f523a14                                    0.0s 
 => => naming to docker.io/library/myspringboot_new                                                                             0.1s 
[root@localhost myspringboot]#  

 

3.运行

docker run -d -p 8888:8888 --name myspringboot_new myspringboot_new:latest

 

4.登录容器

docker exec -ti myspringboot_new /bin/bash

 

image

 

posted @ 2025-08-07 16:52  slnngk  阅读(16)  评论(0)    收藏  举报