Docker-Maven插件

Docker-Maven插件的使用

  1. 修改宿主机的 Docker 配置,让其可以远程访问

    vi /usr/lib/systemd/system/docker.service
    # CentOS
    ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
    # Ubuntu
    ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
    
  2. 刷新配置,重启服务

    sudo systemctl daemon-reload 
    sudo systemctl restart docker
    # 启动私有仓库容器
    docker start ContainerRegistry
    
  3. 检查docker是否监听2375端口

    netstat -anp|grep 2375
    
  4. 在 pom.xml 添加 docker-maven 插件配置


<plugin>
	<groupId>com.spotifygroupId>
	<artifactId>docker-maven-pluginartifactId>
	<version>1.0.0version>
	<configuration>
		
		<registryUrl>123.207.4.93:5000registryUrl>
		<pushImage>truepushImage>
		
		<imageName>123.207.4.93:5000/mir-dockerimageName>
		
		<baseImage>javabaseImage>
		
		<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]entryPoint>
		<resources>
			<resource>
				<targetPath>/targetPath>
				<directory>${project.build.directory}directory>
				<include>${project.build.finalName}.jarinclude>
			resource>
		resources>
		
		<dockerHost>http://123.207.4.93:2375dockerHost>
	configuration>
plugin>

以上配置会自动生成 Dockerfile 文件

  1. 生成并 Push 到服务器上就 OK 了

    mvn clean package docker:build -DpushImage
    

你可能感兴趣的:(CI/CD-OpsDev)