0

0

怎么利用Dockerfile部署SpringBoot项目

王林

王林

发布时间:2023-05-13 17:55:06

|

1473人浏览过

|

来源于亿速云

转载

1、创建一个springbooot项目并且打成jar包

怎么利用Dockerfile部署SpringBoot项目

2、在linux中创建一个文件夹,来做docker测试

[root@izwz90lvzs7171wgdhul8az ~]# mkdir /root/docker_test

3、将jar包上传到linux中

创建存放jar包的文件夹

[root@izwz90lvzs7171wgdhul8az docker_test]# mkdir /root/docker_test/jar

然后利用xshell上传jar包到上面的文件夹中

4、编写dockerfile文件

# 基于java镜像创建新镜像
from java:8
# 作者
maintainer howinfun
# 将jar包添加到容器中并更名为app.jar
add jar/app.jar /root/docker_test/app.jar
# 运行jar包
entrypoint ["nohup","java","-jar","/root/docker_test/app.jar","&"]

注意:add 、 copy 指令用法一样,唯一不同的是 add 支持将归档文件(tar, gzip, bzip2, etc)做提取和解压操作。还有需要注意的是,copy 指令需要复制的目录一定要放在 dockerfile 文件的同级目录下。

5、制作镜像

[root@izwz90lvzs7171wgdhul8az docker_test]# docker build -t sbdemo .

命令参数:

雾象
雾象

WaytoAGI推出的AI动画生成引擎

下载

-t:指定新镜像名
.:表示dockfile在当前路径

如果我们的 dockerfile 文件路径不在这个目录下,或者有另外的文件名,我们可以通过 -f 选项单独给出 dockerfile 文件的路径

[root@izwz90lvzs7171wgdhul8az docker_test]# docker build -t sbdemo -f /root/docker_test/dockerfile /root/docker_test/

命令参数:

-f:第一个参数是dockerfile的路径 第二个参数是dockerfile所在文件夹制作完成后通过docker images命令查看我们制作的镜像:

[root@izwz90lvzs7171wgdhul8az docker_test]# docker images | grep sbdemo
sbdemo       latest       7efac46ef997    4 hours ago     686mb

6、启动容器

[root@izwz90lvzs7171wgdhul8az docker_test]# docker run -d -p 8888:8888 --name mysbdemo sbdemo:latest

命令参数:

-d:后台运行
-p:公开指定端口号
--name:给容器命名

启动后可通过docker ps查看正在运行的容器:

[root@izwz90lvzs7171wgdhul8az docker_test]# docker ps
container id    image        command         created       status       ports          names
5096c8c7b36f    sbdemo       "nohup java -jar /ro??  4 seconds ago    up 2 seconds    0.0.0.0:8888->8888/tcp  mysbdemo

7、查看容器启动日志

我们可以通过 docker logs 查看指定容器的日志:

[root@izwz90lvzs7171wgdhul8az docker_test]# docker logs mysbdemo

 .  ____     _      __ _ _
 /\ / ___'_ __ _ _(_)_ __ __ _    
( ( )___ | '_ | '_| | '_ / _` |    
 \/ ___)| |_)| | | | | || (_| | ) ) ) )
 ' |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: spring boot ::    (v2.1.6.release)

2019-10-11 02:10:46.264 info 1 --- [      main] com.hyf.databaseapplication       : starting databaseapplication v0.0.1-snapshot on 6d85ac5d8751 with pid 1 (/root/docker_test/app.jar started by root in /)
2019-10-11 02:10:46.267 debug 1 --- [      main] com.hyf.databaseapplication       : running with spring boot v2.1.6.release, spring v5.1.8.release
2019-10-11 02:10:46.268 info 1 --- [      main] com.hyf.databaseapplication       : no active profile set, falling back to default profiles: default
2019-10-11 02:10:49.139 warn 1 --- [      main] o.m.s.mapper.classpathmapperscanner   : skipping mapperfactorybean with name 'bookmapper' and 'com.hyf.mapper.bookmapper' mapperinterface. bean already defined with the same name!
2019-10-11 02:10:49.139 warn 1 --- [      main] o.m.s.mapper.classpathmapperscanner   : no mybatis mapper was found in '[com.hyf]' package. please check your configuration.
2019-10-11 02:10:49.246 info 1 --- [      main] .s.d.r.c.repositoryconfigurationdelegate : multiple spring data modules found, entering strict repository configuration mode!
2019-10-11 02:10:49.257 info 1 --- [      main] .s.d.r.c.repositoryconfigurationdelegate : bootstrapping spring data repositories in default mode.
2019-10-11 02:10:49.328 info 1 --- [      main] .s.d.r.c.repositoryconfigurationdelegate : finished spring data repository scanning in 39ms. found 0 repository interfaces.
2019-10-11 02:10:50.345 info 1 --- [      main] trationdelegate$beanpostprocessorchecker : bean 'org.springframework.transaction.annotation.proxytransactionmanagementconfiguration' of type [org.springframework.transaction.annotation.proxytransactionmanagementconfiguration$$enhancerbyspringcglib$$2c6b335] is not eligible for getting processed by all beanpostprocessors (for example: not eligible for auto-proxying)
2019-10-11 02:10:51.255 info 1 --- [      main] o.s.b.w.embedded.tomcat.tomcatwebserver : tomcat initialized with port(s): 8888 (http)
2019-10-11 02:10:51.359 info 1 --- [      main] o.apache.catalina.core.standardservice  : starting service [tomcat]
2019-10-11 02:10:51.359 info 1 --- [      main] org.apache.catalina.core.standardengine : starting servlet engine: [apache tomcat/9.0.21]
2019-10-11 02:10:51.778 info 1 --- [      main] o.a.c.c.c.[tomcat].[localhost].[/]    : initializing spring embedded webapplicationcontext
2019-10-11 02:10:51.779 info 1 --- [      main] o.s.web.context.contextloader      : root webapplicationcontext: initialization completed in 5104 ms
2019-10-11 02:10:54.164 info 1 --- [      main] o.s.s.concurrent.threadpooltaskexecutor : initializing executorservice 'applicationtaskexecutor'
2019-10-11 02:10:56.081 info 1 --- [      main] o.s.b.w.embedded.tomcat.tomcatwebserver : tomcat started on port(s): 8888 (http) with context path ''
2019-10-11 02:10:56.090 info 1 --- [      main] com.hyf.databaseapplication       : started databaseapplication in 11.49 seconds (jvm running for 12.624)

8、访问接口

容器启动后,我们尝试使用postman或者其他http工具去访问部署在容器中的应用接口。

怎么利用Dockerfile部署SpringBoot项目

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

WorkBuddy
WorkBuddy

腾讯云推出的AI原生桌面智能体工作台

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
软件测试常用工具
软件测试常用工具

软件测试常用工具有Selenium、JUnit、Appium、JMeter、LoadRunner、Postman、TestNG、LoadUI、SoapUI、Cucumber和Robot Framework等等。测试人员可以根据具体的测试需求和技术栈选择适合的工具,提高测试效率和准确性 。

463

2023.10.13

硬盘接口类型介绍
硬盘接口类型介绍

硬盘接口类型有IDE、SATA、SCSI、Fibre Channel、USB、eSATA、mSATA、PCIe等等。详细介绍:1、IDE接口是一种并行接口,主要用于连接硬盘和光驱等设备,它主要有两种类型:ATA和ATAPI,IDE接口已经逐渐被SATA接口;2、SATA接口是一种串行接口,相较于IDE接口,它具有更高的传输速度、更低的功耗和更小的体积;3、SCSI接口等等。

1926

2023.10.19

PHP接口编写教程
PHP接口编写教程

本专题整合了PHP接口编写教程,阅读专题下面的文章了解更多详细内容。

656

2025.10.17

php8.4实现接口限流的教程
php8.4实现接口限流的教程

PHP8.4本身不内置限流功能,需借助Redis(令牌桶)或Swoole(漏桶)实现;文件锁因I/O瓶颈、无跨机共享、秒级精度等缺陷不适用高并发场景。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

2397

2025.12.29

java接口相关教程
java接口相关教程

本专题整合了java接口相关内容,阅读专题下面的文章了解更多详细内容。

47

2026.01.19

硬盘接口类型介绍
硬盘接口类型介绍

硬盘接口类型有IDE、SATA、SCSI、Fibre Channel、USB、eSATA、mSATA、PCIe等等。详细介绍:1、IDE接口是一种并行接口,主要用于连接硬盘和光驱等设备,它主要有两种类型:ATA和ATAPI,IDE接口已经逐渐被SATA接口;2、SATA接口是一种串行接口,相较于IDE接口,它具有更高的传输速度、更低的功耗和更小的体积;3、SCSI接口等等。

1926

2023.10.19

PHP接口编写教程
PHP接口编写教程

本专题整合了PHP接口编写教程,阅读专题下面的文章了解更多详细内容。

656

2025.10.17

php8.4实现接口限流的教程
php8.4实现接口限流的教程

PHP8.4本身不内置限流功能,需借助Redis(令牌桶)或Swoole(漏桶)实现;文件锁因I/O瓶颈、无跨机共享、秒级精度等缺陷不适用高并发场景。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

2397

2025.12.29

C# ASP.NET Core微服务架构与API网关实践
C# ASP.NET Core微服务架构与API网关实践

本专题围绕 C# 在现代后端架构中的微服务实践展开,系统讲解基于 ASP.NET Core 构建可扩展服务体系的核心方法。内容涵盖服务拆分策略、RESTful API 设计、服务间通信、API 网关统一入口管理以及服务治理机制。通过真实项目案例,帮助开发者掌握构建高可用微服务系统的关键技术,提高系统的可扩展性与维护效率。

76

2026.03.11

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Redis6入门到精通超详细教程
Redis6入门到精通超详细教程

共47课时 | 5.6万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号