1、使用docker部署springboot项目打成的jar包。
2、将打好的jar包和dockerfile文件放在同级目录下。(dockerfile如下:)
# 基础镜像使用java FROM java:8 # 作者 MAINTAINER yin <2481771431@qq.com> # VOLUME 指定了临时文件目录为/tmp。 # 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp VOLUME /tmp # 将jar包添加到容器中并更名为app.jar ADD boot-rabbitmq-0.0.1-SNAPSHOT.jar app.jar # 运行jar包 RUN bash -c 'touch /app.jar' ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]3、windows系统直接拖拽文件到centos(使用xshell连接)需要安装 yum install lrzsz,将jar文件和dockerfile文件拖拽同一级目录。
4、启动docker(systemctl start docker ).
5、打包docker镜像 docker build -t 镜像名字 . 注意后面的 . (打包镜像是一个过程:)
[root@localhost dock]# docker build -t bootmq . Sending build context to Docker daemon 19.9MB Step 1/6 : 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/6 : MAINTAINER yin <2481771431@qq.com> ---> Running in 9e86e0462282 Removing intermediate container 9e86e0462282 ---> f572a59447d9 Step 3/6 : VOLUME /tmp ---> Running in da983d08fbd7 Removing intermediate container da983d08fbd7 ---> 1e865d903bf2 Step 4/6 : ADD boot-rabbitmq-0.0.1-SNAPSHOT.jar app.jar ---> 2f9737acfe38 Step 5/6 : RUN bash -c 'touch /app.jar' ---> Running in d27c0f391dfa Removing intermediate container d27c0f391dfa ---> 72874e2e22fe Step 6/6 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] ---> Running in 8cbb9853a090 Removing intermediate container 8cbb9853a090 ---> 5347558763b9 Successfully built 5347558763b9 Successfully tagged bootmq:latest6、查看镜像 docker images
[root@localhost dock]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE bootmq latest 5347558763b9 57 seconds ago 683MB mysql 5.7 718a6da099d8 4 weeks ago 448MB java 8 d23bdf5b1b1b 3 years ago 643MB7、启动容器 docker run -d -p 8089:8080 bootmq
8、浏览器访问 ip+:8089/+路径
整体结构图: