Dockerfile 文件java
FROM openjdk:8-jdk-alpine VOLUME /tmp ADD testdocker-1.0-SNAPSHOT.jar app.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
1.在centos7 ~ 建立一個文件夾docker 裏面放置 上面的Dockerfile 和 springBoot 打包的項目docker_spring_boot.jarspring
[root@sl docker]# ls Dockerfile testdocker-1.0-SNAPSHOT.jar
在該docker文件下 指令:docker build -t docker .docker
docker build -t docker .
-t表明要構建的鏡像的tagcentos
.表明當前目錄,也就是Dockerfile所在的目錄。瀏覽器
執行docker build命令,docker就會根據Dockerfile裏你定義好的命令進行構建新的鏡像。服務器
而後就能夠看到在下載各類依賴的maven、各類jar,構建完畢後,啓動項目。app
在該docker文件下使用 指令:dom
docker run -d -p 8080:8080 docker
運行該springBoot項目,能夠看到構建完畢的景象docker了maven
查詢當前運行的容器tcp
[root@sl docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f1d7587c800e cdaa62cb062c "java -Djava.secur..." 2 hours ago Up 2 hours 0.0.0.0:8088->8088/tcp kickass_liskov
最後,訪問瀏覽器:
把整個工程代碼拷到centos服務器上 [root@iz2zeh5mjwg5u2vl2fawchz ~]# ls /usr/local/gs-spring-boot-docker-master pom.xml src target
在/usr/local/gs-spring-boot-docker-master目錄下運行命令:
mvn package docker:build
success
---> 8b562204cb2c Removing intermediate container 262ca4a9b39d Step 5/6 : ENV JAVA_OPTS "" ---> Running in 19a713bcc1fa ---> 772752e84c58 Removing intermediate container 19a713bcc1fa Step 6/6 : ENTRYPOINT sh -c java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar ---> Running in e43743f6b521 ---> 831237777bc5 Removing intermediate container e43743f6b521 Successfully built 831237777bc5 [INFO] Built springio/gs-spring-boot-docker-master [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 32.046s [INFO] Finished at: Thu Jun 21 10:29:30 CST 2018 [INFO] Final Memory: 34M/83M [INFO] ------------------------------------------------------------------------
看到build success說明該項目的鏡像建立成功,查看一下
docker images
運行該鏡像
docker run -p 8010:8010 -t springio/gs-spring-boot-docker-master