1. Eclipse安装Docker Tools插件

 

安装完成截图:

 

2. 本地环境变量配置如下:

3. 连接远程docker服务器的方法

  修改docker的配置文件

         [root@centos7 ~]# cat  /etc/docker/daemon.json

         {"hosts":["tcp://0.0.0.0:2376","unix:///var/run/docker.sock"]}

         这样远程可以通过2376端口连接到docker

4. 打开远程资源区

5. 在pom.xml文件中增加插件配置

    <build>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>

            <!-- dockermaven插件,官网:https://github.com/spotify/docker-maven-plugin -->

            <plugin>

                <groupId>com.spotify</groupId>

                <artifactId>docker-maven-plugin</artifactId>

                <version>0.4.12</version>

                <configuration>

                    <!-- 注意imageName一定要是符合正则[a-z0-9-_.]的,否则构建不会成功 -->

                    <!-- 详见:https://github.com/spotify/docker-maven-plugin Invalid repository

                        name ... only [a-z0-9-_.] are allowed -->

                    <imageName>docker-demo</imageName>

                    <baseImage>java</baseImage>

                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>

                    <resources>

                        <resource>

                            <targetPath>/</targetPath>

                            <directory>${project.build.directory}</directory>

                            <include>${project.build.finalName}.jar</include>

                        </resource>

                    </resources>

                </configuration>

            </plugin>

        </plugins>

    </build>

6.进入代码目录,执行命令“mvn clean package docker:build”项目编

译成功。

7.启动docker容器

执行命令“docker run -p 8080:8080 docker-demo:latest”,使用镜像docker-demo:latest启动docker容器。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐