搭建docker 开发环境

IDEA中应用DOCKER

环境说明

  1. IDEA 版本:IntelliJ IDEA 2020.1 (Ultimate Edition)
  2. Docker 版本:Docker desktop community 2.3.0.4
  3. 操作系统:window10 企业版

在IDEAL中安装DOCKER插件

  1. 对外暴露 Docker 的 2375端口

     

    image-20200914095045629

  2. 在 IDEA 中安装 Docker 插件

     

    image-20200914095117695

创建并部署普通Maven项目

  1. 创建普通 Maven Web 项目

     

    image-20200914100344952

  2. 在 pom.xml 中添加 Docker 依赖

    <?xml version="1.0" encoding="UTF-8"?>
    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    
      <properties>
        <docker.image.prefix>Yacon</docker.image.prefix>
      </properties>
    
      <build>
        <pluginManagement>...</pluginManagement>
        <plugins>
          <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>1.0.0</version>
            <configuration>
              <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
              <dockerDirectory></dockerDirectory>
              <resources>
                <resource>
                  <targetPath>/</targetPath>
                  <directory>${project.build.directory}</directory>
                  <include>${project.build.finalName}.jar</include>
                </resource>
              </resources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
  1. 编写 Dockerfile 文件

     

    image-20200914101256693

    FROM tomcat:8.5
    ADD target/*.war /usr/local/tomcat/webapps/
    EXPOSE 8080
  1. 链接本地 Docker

     

    添加配置

     

    image-20200914101441055

     

    选择Dockerfile

     

    image-20200914101614987

    链接本地Docker

     

    image-20200914101740187

    image-20200914101838027

    配置镜像基本信息

     

    image-20200914102500133

    端口映射配置

     

    image-20200914102615241

    映射数据卷

     

    此案例无须配置

     

    image-20200914102906673

  2. 项目部署

     

    image-20200914103029831

    image-20200914103119158

     

    image-20200914103140483

     

    image-20200914103437156

  3. 运行项目

     

    容器启动

     

    image-20200914103513820

     

    访问测试

    http://localhost/myblog/
posted @ 2021-06-09 12:35  编码小高  阅读(167)  评论(0编辑  收藏  举报