springboot项目打包成docker镜像
参考mall在Linux环境下的部署(基于Docker容器)首先我们的服务器要有docker私有仓库docker registry搭建下载镜像docker pull registry:2启动容器(随docker自启)docker run -d -p 5000:5000--name registry2-noauth --restart=always-v /usr/local/docker/regis
·
参考mall在Linux环境下的部署(基于Docker容器)
首先我们的服务器要有docker私有仓库
docker registry搭建
下载镜像
docker pull registry:2
启动容器(随docker自启)
docker run -d -p 5000:5000 --name registry2-noauth --restart=always -v /usr/local/docker/registry/auth/:/auth/ -v /usr/local/docker/registry/:/var/lib/registry/ registry:2.6.2
客户端配置免https
echo '{ "insecure-registries":["172.16.1.146:5000"] }' > /etc/docker/daemon.json
修改docker.service文件
vim /usr/lib/systemd/system/docker.service
将ExecStart的值修改为/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
重载docker
systemctl daemon-reload
systemctl restart docker
用maven将springboot项目构建到docker私服仓库
<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.1.0</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>mall/${project.artifactId}:${project.version}</imageName>
<dockerHost>${docker.host}</dockerHost>
<baseImage>java:8</baseImage>
<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${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>
其中${docker.host}的值应该改为自己的docker所在服务器的公网ip。
更多推荐
所有评论(0)