docker部署springboot项目(详细教程)(1)

1.更新软件源

第一个命令

yum update

在这里插入图片描述

遇到他输入y,然后回车,看到下面信息表示更新成功:

在这里插入图片描述

第二个命令

yum install -y yum-utils device-mapper-persistent-data lvm2

在这里插入图片描述

2.添加docker稳定版本的yum软件源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

在这里插入图片描述

3.再次更新yum源,并安装docker

yum update

在这里插入图片描述

yum install -y docker-ce

在这里插入图片描述

看到这个页面,标识docker已经安装成功了。

4.安装完成之后启动docker

systemctl start docker

5.重启

systemctl restart docker

6.停止

systemctl stop docker

7.开机自启动

systemctl enable docker

8.查看docker的状态

systemctl status docker

通过脚本安装


除了上面的yum安装,还可以采用shell脚本安装,安装流程如下:

curl -fsSL https://get.docker.com/ | sh

或者

wget -qO- https://get.docker.com/ | sh

拉取java环境

=======================================================================

拉取jdk很简单,直接执行一行代码即可,我这里拉取的时java 8的版本。

docker pull java:8

拉取完成之后执行:

docker images

如果出现下面内容,表示拉取成功

在这里插入图片描述

创建springboot项目

=============================================================================

1.新建项目

在这里插入图片描述

引入sprint-boot-web的依赖

在这里插入图片描述

新建完成之后的项目结构

在这里插入图片描述

2.引入docker依赖

<docker.image.prefix>registry.aliyuncs.com/linhuatest</docker.image.prefix>

com.spotify

docker-maven-plugin

1.0.0

d o c k e r . i m a g e . p r e f i x / {docker.image.prefix}/ docker.image.prefix/{project.artifactId}

src/main/docker

/

${project.build.directory}

${project.build.finalName}.jar

3.新建docker文件

在main目录下新建docker目录,然后在docker目录下创建dockerfile文件,不需要后缀名。

在这里插入图片描述

创建完成之后的工程目录如下:

在这里插入图片描述

4.编辑dockerfile文件

FROM java:8

VOLUME /tmp/tomcat

ADD spring-boot-docker-0.0.1-SNAPSHOT.jar springboot-docker.jar

ENTRYPOINT [“java”,“-Djava.security.egd=file:/dev/./urandom”,“-jar”,“/springboot-docker.jar”]

FROM:指定存在的镜像,java:8是我刚刚拉取的镜像,运行的基础。

VOLUME:指向的一个临时文件,用于存储tomcat工作。

ADD:复制文件并且重命名文件。

ENTRYPOINT:初始化配置或者自定义配置。

5.创建测试接口

在这里插入图片描述

TestController内容如下:

package com.ymy.controller;

import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RestController;

@RestController

@Slf4j

public class TestController {

@RequestMapping(value = “/test”,method = RequestMethod.GET)

public String test(){

System.out.println(“这是控制台日志!”);

log.info(“这是输出到文件的日志”);

return “HELLO-BUG!!!!!!!!!!”;

}

}

在resources目录下创建log4j2.xml文件

主要看这两个参数:

在这里插入图片描述

这里我使用了log4j2的日志,如何配置log4j2的日志,请参考 springboot整合Log4j2(将日志输出到指定文件)

6.编写application.yml配置文件

server:

port: 9999

到这里springboot项目就创建完成了,我们现在启动一下项目。

. ____ _ __ _ _

/\ / _ __ _ () __ __ _ \ \ \ \

( ( )___ | '_ | '| | ’ / _` | \ \ \ \

\/ _)| |)| | | | | || (| | ) ) ) )

’ || .__|| ||| |__, | / / / /

=|_|======|/=////

:: Spring Boot :: (v2.2.5.RELEASE)

15:29:19.386 [main] INFO com.ymy.SpringBootDockerApplication - Starting SpringBootDockerApplication on LAPTOP-3GLHJRE9 with PID 20652 (D:\springboot\spring-boot-docker\target\classes started by admin in D:\springboot)

15:29:19.395 [main] INFO com.ymy.SpringBootDockerApplication - No active profile set, falling back to default profiles: default

15:29:20.183 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat initialized with port(s): 9999 (http)

15:29:20.200 [main] INFO org.apache.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler [“http-nio-9999”]

15:29:20.201 [main] INFO org.apache.catalina.core.StandardService - Starting service [Tomcat]

15:29:20.201 [main] INFO org.apache.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.31]

15:29:20.309 [main] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext

15:29:20.309 [main] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 881 ms

15:29:20.452 [main] INFO org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor - Initializing ExecutorService ‘applicationTaskExecutor’

15:29:20.568 [main] INFO org.apache.coyote.http11.Http11NioProtocol - Starting ProtocolHandler [“http-nio-9999”]

15:29:20.596 [main] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer - Tomcat started on port(s): 9999 (http) with context path ‘’

15:29:20.599 [main] INFO com.ymy.SpringBootDockerApplication - Started SpringBootDockerApplication in 1.664 seconds (JVM running for 4.04)

结尾

查漏补缺:Java岗 千+道面试题Java基础+全家桶+容器+反射+异常等

这不止是一份面试清单,更是一种”被期望的责任“,因为有无数个待面试者,希望从这篇文章中,找出通往期望公司的”钥匙“,所以上面每道选题都是结合我自身的经验于千万个面试题中经过艰辛的两周,一个题一个题筛选出来再次对好答案和格式做出来的,面试的答案也是再三斟酌,深怕误人子弟是小,影响他人仕途才是大过,也希望您能把这篇文章分享给更多的朋友,让他帮助更多的人,帮助他人,快乐自己,最后,感谢您的阅读。

由于细节内容实在太多啦,在这里我花了两周的时间把这些答案整理成一份文档了,在这里只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!

20.599 [main] INFO com.ymy.SpringBootDockerApplication - Started SpringBootDockerApplication in 1.664 seconds (JVM running for 4.04)

结尾

[外链图片转存中…(img-Oe7K1dGB-1714286891099)]

这不止是一份面试清单,更是一种”被期望的责任“,因为有无数个待面试者,希望从这篇文章中,找出通往期望公司的”钥匙“,所以上面每道选题都是结合我自身的经验于千万个面试题中经过艰辛的两周,一个题一个题筛选出来再次对好答案和格式做出来的,面试的答案也是再三斟酌,深怕误人子弟是小,影响他人仕途才是大过,也希望您能把这篇文章分享给更多的朋友,让他帮助更多的人,帮助他人,快乐自己,最后,感谢您的阅读。

由于细节内容实在太多啦,在这里我花了两周的时间把这些答案整理成一份文档了,在这里只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 27
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值