1.场景
stringboot - > spring boot .jar -> dockerfile---> run dokcerfile
2.编写springboot 项目打包上传linux服务器
2.1 将jar 包和 docker放到同一个目录
-rw-r--r-- 1 root root 19514674 2月 27 22:48 myspringbootdocker.jar
[root@basenode springbootdocker]# pwd
/opt/springbootdocker
[root@basenode springbootdocker]#
2.2 编写dockerfile
1.需要注意的是 jar包名字不能有大写
2.Dockerfile 的文件名 首字母D 必须大写
[root@basenode springbootdocker]# vi Dockerfile
# 基础镜像使用java
FROM java:8
# 作者
MAINTAINER wudl
# VOLUME 指定临时文件目录为/tmp,在主机/var/lib/docker目录下创建了一个临时文件并链接到容器的/tmp
VOLUME /tmp
# 将jar包添加到容器中并更名为zzyy_docker.jar
ADD myspringbootdocker.jar /myspringbootdocker.jar
# 运行jar包
RUN bash -c 'touch /myspringbootdocker.jar'
ENTRYPOINT ["java","-jar","/myspringbootdocker.jar"]
#暴露18088端口作为微服务
EXPOSE 18088
3. 运行dockerfile
命令 docker build -t myspringbootdocker:1.6 .
[root@basenode springbootdocker]# docker build -t myspringbootdocker:1.6 .
Sending build context to Docker daemon 19.52MB
Step 1/7 : FROM java:8
8: Pulling from library/java
5040bd298390: Pull complete
fce5728aad85: Pull complete
76610ec20bf5: Pull complete
60170fec2151: Pull complete
e98f73de8f0d: Pull complete
11f7af24ed9c: Pull complete
49e2d6393f32: Pull complete
bb9cdec9c7f3: Pull complete
Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
Status: Downloaded newer image for java:8
---> d23bdf5b1b1b
Step 2/7 : MAINTAINER wudl
---> Running in 91addd3bc917
Removing intermediate container 91addd3bc917
---> 7982d20f4554
Step 3/7 : VOLUME /tmp
---> Running in 6973feea6ef5
Removing intermediate container 6973feea6ef5
---> c2feccd04de7
Step 4/7 : ADD myspringbootdocker.jar /myspringbootdocker.jar
---> fa79952fe484
Step 5/7 : RUN bash -c 'touch /myspringbootdocker.jar'
---> Running in f75bf573ec70
Removing intermediate container f75bf573ec70
---> 6d82fe109ae7
Step 6/7 : ENTRYPOINT ["java","-jar","/myspringbootdocker.jar"]
---> Running in 3fce2f523b70
Removing intermediate container 3fce2f523b70
---> 80ef7731c159
Step 7/7 : EXPOSE 18088
---> Running in 2d1179d0cfb4
Removing intermediate container 2d1179d0cfb4
---> 3f4e689e54db
Successfully built 3f4e689e54db
Successfully tagged myspringbootdocker:1.6
[root@basenode springbootdocker]#
4.查看镜像
[root@basenode springbootdocker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myspringbootdocker 1.6 3f4e689e54db 2 minutes ago 682MB
centosjava8 1.5 14fad190b338 4 weeks ago 801MB
nacos/nacos-server v2.0.4 ea54f31c46e4 5 weeks ago 1.07GB
tomcat latest fb5657adc892 2 months ago 680MB
mysql 5.7 c20987f18b13 2 months ago 448MB
apache/incubator-doris build-env-latest cc924653f13d 2 months ago 4.24GB
apache/incubator-doris build-env-for-0.15.0 e568f7b2e1d8 3 months ago 3.54GB
5. 运行镜像
docker run -d -p 18089:18088 3f4e689e54db
[root@basenode springbootdocker]# docker run -d -p 18089:18088 3f4e689e54db
5040141bd7d5700d8310a70309f940bb452656c0e909c6c6e138f7f6a9f65295
[root@basenode springbootdocker]#
6. 运行
到此这篇关于springboot运行到dokcer中 dockerfile的文章就介绍到这了,更多相关springboot运行dockerfile内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!