docker dockerfile的使用

构建镜像

首先创建dockerfile 文件夹

然后创建dockerfile文件

[root@localhost Dockerfile]# mkdir Dockerfile2
[root@localhost Dockerfile]# cd Dockerfile2
[root@localhost Dockerfile2]# vi Dockerfile
# 指定基础镜像,本地没有会从dockerHub pull下来
FROM java:8
# 把可执行jar包复制到基础镜像的根目录下 
ADD demo.jar /demo.jar
# 镜像要暴露的端口,如要使用端口,在执行docker run命令时使用-p生效
EXPOSE 8081
# 在镜像运行为容器后执行的命令
ENTRYPOINT ["java","-jar","/demo.jar"]
# 构建镜像
[root@localhost Dockerfile2]# docker build -t demo .

运行自己的 SpringBoot 镜像
[root@localhost Dockerfile2] docker run --name demo -d -p 8081:8081 demo

执行命令后可以看到我们熟悉的springboot开机启动界面了

[root@localhost Dockerfile2]# docker logs demo

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.5.RELEASE)

2020-03-25 03:38:57.321  INFO 1 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on 75e52477616b with PID 1 (/demo.jar started by root in /)
2020-03-25 03:38:57.330  INFO 1 --- [           main] com.example.demo.DemoApplication         : The following profiles are active: dev
2020-03-25 03:38:59.872  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-03-25 03:38:59.878  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2020-03-25 03:38:59.978  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 35ms. Found 0 Redis repository interfaces.
2020-03-25 03:39:02.664  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2020-03-25 03:39:02.738  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-03-25 03:39:02.739  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-25 03:39:03.047  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-03-25 03:39:03.047  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 5495 ms

在网页是执行demo接口效果如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值