ubuntu18下Docker运行springboot项目

1.springboot项目打成jar包

mvn install

2.编写Dockerfile

# 基础镜像使用java
FROM java:8
# 作者
#MAINTAINER sk
# VOLUME 指定了临时文件目录为/tmp。
# 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp
VOLUME /tmp
# 将jar包添加到容器中并更名为app.jar
ADD demo1-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.把jar包和Dockerfile放在同一个文件夹里(a)

4.进入文件夹然后运行

root@songke-ubuntu:~/Study/IdeaProjects/demo1/a# docker build -t demo1 .

5.等待

root@songke-ubuntu:~/Study/IdeaProjects/demo1/a# docker build -t demo1 .
Sending build context to Docker daemon  16.82MB
Step 1/5 : 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/5 : VOLUME /tmp
 ---> Running in aa43baf235ca
Removing intermediate container aa43baf235ca
 ---> 423688a3a9ac
Step 3/5 : ADD demo1-0.0.1-SNAPSHOT.jar app.jar
 ---> ab141a560b8a
Step 4/5 : RUN bash -c 'touch /app.jar'
 ---> Running in 50be93095281
Removing intermediate container 50be93095281
 ---> 731c8eed60b1
Step 5/5 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
 ---> Running in 6af0288a3a44
Removing intermediate container 6af0288a3a44
 ---> eb5273196a7e
Successfully built eb5273196a7e
Successfully tagged demo1:latest

6.查看

docker images

7.运行

docker run -d -p 8099:8080 demo1

8.输入地址验证

http://localhost:8099/demo1/

你可能感兴趣的:(ubuntu18下Docker运行springboot项目)