1.配置 Docker Remote API
vi /usr/lib/systemd/system/docker.service
直接在 ExecStart 启动参数的 /usr/bin/dockerd 后面添加以开启 TCP 连接:-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
重新载入 systemd systemctl daemon-reload
重启docker
本地测试:curl http://localhost:2375/info 远程测试 ip:2375/info 返回json数据 远程不好使 可能是防火墙问题
2.最好在Linux服务 现准备好父镜像
3.Springboot添加docker-maven-plugin 插件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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.4.RELEASE</version> </parent> <version>1.0.0-SNAPSHOT</version> <artifactId>demo</artifactId> <packaging>jar</packaging> <name>demo</name> <description>Spring Boot</description> <properties> <weixin-java-mp.version>3.4.0</weixin-java-mp.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.locales>zh_CN</project.build.locales> <docker.image.prefix>wechat-mp-demo</docker.image.prefix> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </exclusion> </exclusions> </dependency> <!-- Testing Dependencies --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </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> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerHost>http://192.168.137.200:2375</dockerHost> <dockerDirectory>src/main/docker</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build> </project>
4.打包
mvn clean package
mvn clean package docker:build
来源:oschina
链接:https://my.oschina.net/u/3777103/blog/3082286