The maven plugin is used to package the SpringBoot project image and push it to the specified server.

Author: IT Wang Xiaoer blog: itwxe.com

Docker enable remote API

Note that the docker remote API port is exposed and other people only need to know your IP and port, so they can operate your server.

Therefore, you need to configure ACL and LTS for public network servers. If required, you can search for information to solve security problems.

Enable the access port.

firewall-cmd --zone=public --add-port=2375/tcp --permanent
firewall-cmd --reload
Copy the code

Open docker.service file editing.

vim /usr/lib/systemd/system/docker.service
Copy the code

Modify information.

# Modify the previous information
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
# Modified informationExecStart = / usr/bin/dockerd -h TCP: / / 0.0.0.0:2375 - H Unix: / / var/run/docker. The sockCopy the code

Refresh the configuration for the configuration to take effect, and restart the Docker.

systemctl daemon-reload
systemctl restart docker
Copy the code

Ii. Project transformation

Pom.xml adds content.

<plugin>
	<groupId>com.spotify</groupId>
	<artifactId>docker-maven-plugin</artifactId>
	<version>1.1.0</version>
	<executions>
		<execution>
			<id>build-image</id>
			<! Docker :build -->
			<phase>package</phase>
			<goals>
				<goal>build</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<! ${project.artifactId} specifies the name of the mirror. ${project.version} specifies the version.
		<imageName>itwxe/${project.artifactId}:${project.version}</imageName>
		<! Docker server address -->
		<dockerHost>http://192.168.5.33:2375</dockerHost>
		<! If the server does not have this base image, it is best to pull it down to prevent timeout.
		<baseImage>java:8</baseImage>
		<! Docker container startup command -->
		<entryPoint>["java", "-jar","/${project.build.finalName}.jar"]
		</entryPoint>
		<resources>
			<resource>
				<! Copy the packaged resource files to this directory -->
				<targetPath>/</targetPath>
				<! The default directory for copying files is target. Maven-jar packages are stored in the target directory.
				<directory>${project.build.directory}</directory>
				<! -- Files to copy, packaged application JAR package, i.e. sunny-admin.jar -->
				<include>${project.build.finalName}.jar</include>
			</resource>
		</resources>
	</configuration>
</plugin>
Copy the code

Save and package the project.

mvn clean package
Copy the code

If you see the following result, it means that the package image has been successfully uploaded to the server.

Create a container by uploading the image and see that the project is accessible.

Docker run -d --name sunny9090 -p 9090:9002 ITwXE /sunny-admin:0.0.1Copy the code

Now that you’ve read this, please like, comment, follow and bookmark it!