docker部署springboot
概述
使用docker部署springboot项目
部署
编写Dockerfile
wangzheng@wangzheng-ubuntu:~/app$ ls
demo-0.0.1-SNAPSHOT.jar Dockerfile
wangzheng@wangzheng-ubuntu:~/app$ cat Dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD demo-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
docker build 镜像
wangzheng@wangzheng-ubuntu:~/app$ docker build -f ./Dockerfile -t wz/app .
Sending build context to Docker daemon 31.38MB
Step 1/4 : FROM openjdk:8-jdk-alpine
---> 792ff45a2a17
Step 2/4 : VOLUME /tmp
---> Running in 37ac55483c67
Removing intermediate container 37ac55483c67
---> 0225f21dac36
Step 3/4 : ADD demo-0.0.1-SNAPSHOT.jar app.jar
---> bdf8968ed2e5
Step 4/4 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
---> Running in 592ef9340eff
Removing intermediate container 592ef9340eff
---> bc544f9e9913
Successfully built bc544f9e9913
Successfully tagged wz/app:latest
docker run创建新容器并运行
wangzheng@wangzheng-ubuntu:~/app$ docker run -it -p 80:80 wz/app
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE)
2019-02-21 08:41:10.797 INFO 1 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT on a10c7b038ee7 with PID 1 (/app.jar started by root in /)
2019-02-21 08:41:10.816 INFO 1 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-02-21 08:41:15.465 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$110175f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-02-21 08:41:15.766 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$80906491] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-02-21 08:41:17.080 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 80 (http)
2019-02-21 08:41:17.226 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
wangzheng@wangzheng-ubuntu:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0641038046b5 wz/app "java -Djava.securit…" 3 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp gallant_clarke
399ac7866dbb mysql:5.6 "docker-entrypoint.s…" 5 weeks ago Up About an hour 0.0.0.0:12345->3306/tcp mysql