docer:利用Dockerfile构建springboot项目镜像

Dockerfile文件内容:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD xing-yu-gaint-0.0.1-SNAPSHOT.jar  app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar

将对于jar包拷贝到Dockerfile文件同级后执行命令,注意别漏了最后的那个点:

docker build -t xingyu-granter:1.0 .

执行命令后控制台输出:

Sending build context to Docker daemon 44.11 MB
Step 1/5 : FROM openjdk:8-jdk-alpine
Trying to pull repository docker.io/library/openjdk ... 
8-jdk-alpine: Pulling from docker.io/library/openjdk
8e402f1a9c57: Pull complete 
4866c822999c: Pull complete 
a5e04b7d13ab: Pull complete 
Digest: sha256:d2e2716147d1f7fe73b1a9f72a9cff7a7aa92d32eb8de4fffbfddc596e004984
Status: Downloaded newer image for docker.io/openjdk:8-jdk-alpine
 ---> e9ea51023687
Step 2/5 : VOLUME /tmp
 ---> Running in 5e95694f9de9
 ---> 60673958a730
Removing intermediate container 5e95694f9de9
Step 3/5 : ADD xing-yu-gaint-0.0.1-SNAPSHOT.jar app.jar
 ---> 4aa05ce33ea5
Removing intermediate container 6d21c6bcc078
Step 4/5 : ENV JAVA_OPTS ""
 ---> Running in f5a8e1764e7a
 ---> 96cdc1ad3ee4
Removing intermediate container f5a8e1764e7a
Step 5/5 : ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
 ---> Running in df6469fa220b
 ---> 1fbdd10e6643
Removing intermediate container df6469fa220b
Successfully built 1fbdd10e6643

最后显示Successfully built 1fbdd10e6643表示build成功,docker image查看已经构建的镜像:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
xingyu-granter      1.0                 1fbdd10e6643        3 minutes ago       149 MB

创建容器:

docker run -d --name xy-granter -p 18080:18080 xingyu-granter:1.0

查看容器是否启动成功:

[root@iZwz99navp6ed7kg7vy8nhZ xingyu-granter]# docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                      NAMES
c0015e2d1a1c        xingyu-granter:1.0   "/bin/sh -c 'exec ..."   4 seconds ago       Up 3 seconds        0.0.0.0:18080->18080/tcp   xy-granter

你可能感兴趣的:(docker,spring-boot)