在Idea中使用Docker部署SpringBoot项目的详细步骤

 更新时间:2020年09月10日 08:21:05   作者:胸大的请先讲  
这篇文章主要介绍了在Idea中使用Docker部署SpringBoot项目的详细教程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

前言

项目需要:

安装Dockeridea中安装docker插件,并配置docker一个SpringBoot项目创建Dockerfile

一、下载、安装、配置Docker下载Docker

下载地址:官网下载 Docker

安装

一直下一步就行

配置路径:Settings–General 勾选 Expose daemon on tcp://localhost:2375 without TLS

在这里插入图片描述

设置镜像,提高下载镜像的速度https://xaiqlt1z.mirror.aliyuncs.com

在这里插入图片描述

测试是否安装成功

C:\Users\msi>docker -v
Docker version 19.03.12, build 48a66213fe

C:\Users\msi> docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  (amd64)
 3. The Docker daemon created a new container from that image which runs the
  executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
  to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

二、Idea 安装Docker插件

1.安装docker插件在idea中: file--Plugins--Marketplace 搜索 Docker 安装

在这里插入图片描述

2.配置Docker服务

file – 搜索docker – 选择Docker – 右侧添加一个Docker
Connection successful 显示,表示 Docker链接成功

在这里插入图片描述

三、创建SpringBoot项目,修改pom.xmlspringMVC 项目,访问 localhost:8080/hello 显示 hello 字符串

@RequestMapping("/hello")
  @ResponseBody
  public String hello () {
    return "hello";
  }

1.配置pom.xml 文件

<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version> 1.2.1</version>
        <executions>
          <execution>
            <id>build-image</id>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <imageName>${project.artifactId}</imageName>
          <imageTags>
            <imageTag>latest</imageTag>
          </imageTags>
          <dockerDirectory>${project.basedir}</dockerDirectory>
          <dockerHost>http://localhost:2375</dockerHost>
          <resources>
            <resource>
              <targetPath>/</targetPath>
              <directory>${project.build.directory}</directory>
              <include>${project.build.finalName}</include>
            </resource>
          </resources>
        </configuration>
      </plugin>
    </plugins>
  </build>

2.创建Docker 文件

在main文件夹下创建一个docker文件夹,并在里面创建一个Dockerfile文件。xxxxx.jar 是使用maven打包后复制进来的。

在这里插入图片描述

Dockerfile 文件内容:

# From java image, version : 8
FROM java:8

# 挂载app目录
VOLUME /app

# COPY or ADD to image
COPY demo-0.0.1-SNAPSHOT.jar app.jar

RUN bash -c "touch /app.jar"
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

maven打包,将其target目录下的jar包复制进docker目录下。

配置Dockerfile配置

在这里插入图片描述

运行

在这里插入图片描述

运行成功

在这里插入图片描述

测试

使用docker 检查容器是否启动:

在这里插入图片描述

测试项目是否启动:

在这里插入图片描述

总结

今天学了下Docker容器,基本的命令学会了,但是一直没弄懂怎么使用。借此机会就花费时间进行学习。目前只是会用,后面会补上步骤详细描述。

到此这篇关于在Idea中使用Docker部署SpringBoot项目的文章就介绍到这了,更多相关Docker部署SpringBoot项目内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Docker Alpine镜像时区问题完美解决方案

    Docker Alpine镜像时区问题完美解决方案

    这篇文章主要介绍了Docker Alpine镜像时区问题完美解决方案,本文给大家分享两种解决方案供大家参考,需要的朋友可以参考下
    2021-04-04
  • Docker同时安装MySQL和MariaDB的方法步骤

    Docker同时安装MySQL和MariaDB的方法步骤

    这篇文章主要介绍了Docker同时安装MySQL和MariaDB的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-09-09
  • Ollama在Docker下的安装与配置详细教程

    Ollama在Docker下的安装与配置详细教程

    这篇文章主要介绍了如何通过Docker拉取Ollama镜像并运行,包括可视化界面和命令行两种方式,文中通过图文介绍的非常详细,需要的朋友可以参考下
    2025-02-02
  • Docker安装Flink教程

    Docker安装Flink教程

    文章描述了如何在Docker中安装Flink的详细步骤,包括拉取镜像、创建文件夹、编辑yml文件、执行命令、检查Docker-compose版本、赋予操作权限以及通过Web端访问Flink
    2024-11-11
  • 查看Docker停止容器占用的内存的实现方法小结

    查看Docker停止容器占用的内存的实现方法小结

    要查看 Docker 停止的容器占用的内存,可以通过以下几种方法来实现,Docker 提供了一些命令和工具来帮助你管理和监控容器的资源使用情况,需要的朋友可以参考下
    2024-11-11
  • Docker日志太多导致磁盘占满的处理方法

    Docker日志太多导致磁盘占满的处理方法

    这篇文章主要介绍了Docker日志太多导致磁盘占满的处理方法,需要的朋友可以参考下
    2018-10-10
  • Docker 数据卷操作的实现

    Docker 数据卷操作的实现

    这篇文章主要介绍了Docker 数据卷操作的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-06-06
  • Docker容器生命周期 | kill和 stop的区别与联系 | docker pause/ unpause

    Docker容器生命周期 | kill和 stop的区别与联系 | d

    这篇文章主要介绍了Docker容器生命周期 | kill和 stop的区别与联系 | docker pause/ unpause,本讲内容是从 Docker入门到进阶里面抽离出来的内容,从而使原文更加有序、重点突出,需要的朋友可以参考下
    2023-08-08
  • Docker部署Apollo的实现步骤

    Docker部署Apollo的实现步骤

    众所周知分布式配置中心在目前也可以说是企业中项目的标配了,本文主要介绍了Docker 部署Apollo的实现步骤,具有一定的参考价值,感兴趣的可以了解一下
    2024-02-02
  • Docker给容器添加新端口映射两种方法及常用命令

    Docker给容器添加新端口映射两种方法及常用命令

    在使用Docker时容器的端口映射是一个核心概念,它允许容器与宿主机以及外部网络进行通信,这篇文章主要给大家介绍了关于Docker给容器添加新端口映射两种方法及常用命令的相关资料,需要的朋友可以参考下
    2024-07-07

最新评论