1、Docker安装

本人是centos7系统,安装也是按照官方文档进行安装。https://docs.docker.com/install/linux/docker-ce/centos/  ,即
1、sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
2、sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
3、sudo yum-config-manager --enable docker-ce-nightly
4、sudo yum install docker-ce docker-ce-cli containerd.io
5、yum list docker-ce --showduplicates | sort -r
6、sudo yum install docker-ce-18.09.1 docker-ce-cli-18.09.1 containerd.io
7、sudo systemctl start docker
8、sudo docker run hello-world

2、配置docker远程连接端口 (注意斜杠)

vim /usr/lib/systemd/system/docker.service
添加: -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

springboot之docker化

 3.重启docker

 systemctl daemon-reload
 systemctl start docker

4、idea安装插件

springboot之docker化

 5、填写远程docker地址

springboot之docker化

 6、连接远程docker

springboot之docker化

7、创建一个springboot项目,这里不做介绍了

8、springboot pom配置文件

springboot之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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.elk</groupId>
    <artifactId>log</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>log</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.58</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <copy todir="src/main/docker" file="target/${project.artifactId}-${project.version}.${project.packaging}"></copy>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>
View Code

相关文章:

  • 2021-09-23
  • 2021-04-21
  • 2021-05-30
  • 2021-08-16
  • 2021-10-06
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-09
  • 2021-11-28
  • 2022-01-04
  • 2022-12-23
  • 2021-09-04
  • 2021-09-04
  • 2021-07-08
相关资源
相似解决方案