Hi, we meet again. – Storm has been doing a lot of research on docker deployment recently, so this article is a good example for those who want to do it, but let’s get started.

Ps: I couldn’t resist the amway wave, because Storm’s main production tool is Eclipse, and the company also uses this tool uniformly. For this reason, the boss has developed some plug-ins by himself, and this IDE is quite powerful.

But from two months ago, idea began to get out of hand, never go back, wall crack Amway everyone to toss about, you will be fondled. Don’t worry about talking about team reasons or shortcuts, etc., because they’ve already been broken. Solutions are out there, and the best way to do a good job is to do a good job, so let’s do something, hahaha.

The words written in the front

I won’t go into much of the SpringBoot project build process in this article, because there are plenty of them. With a few simple configurations, you can run, but it’s important to check your environment. Including IDE, Maven, Java, and more

Install the docker

Download portal: Docker official website according to your development environment, choose to install the corresponding version (actually the basic use of MAC and WIN is similar) installation is a fool type of software installation, pay attention to set your Docker image storage location, because it is placed in C: disk by default

Set the docker

After starting Docker, you’ll see a Docker whale icon in the taskbar. Right-click on Settings and switch to the General option

Select Expose Daemon on TCP ://localhost:2375 without TLSCopy the code

Expose docker connected ports to the development environment, so that we can connect docker to operate our images and containers

Idea Configures the Docker environment

Docker integration ->Plugins->Install JetBrains plugin ->Plugins->Install JetBrains plugin Enter docker in the search box to see docker Integration, and click the Install button on the right to Install it.

After installation to restart the idea, from the File – > Settings – > Build, Execution, Deployment – > Docker open configuration screen New a docker connection, name at random, Copy the address selected above to the TCP socket option. If “Connection Successful” appears in the box below, the configuration is Successful

Deploy the project to Docker

Project package

The first step is to package the SpringBoot project we have built, using Maven’s build tool. Add the following configuration to the POM file of the SpringBoot project:

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<id>SpringBootApp</id>
						<phase>package</phase>
						<configuration>
							<tasks>
								<copy todir="docker" file="target/${project.artifactId}- ${project.version}.${project.packaging}" />
							</tasks>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
Copy the code

Build the image to deploy the Docker

At this point, we’re starting to get to the key points, which is all preparation. First, create a new docker folder in the project root directory (SRC or mian) to store docker-related files. Create a new Dockerfile (this is the image build file, which tells Docker what environment to prepare for our project).

	FROM java:8u111
	VOLUME /tmp
	ADD *.jar app.jar
	EXPOSE 8088
	ENTRYPOINT ["java"."-jar"."/app.jar"]
	# Ubuntu time zone
	RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Copy the code

The above configuration shows that our project runs in the Java8 environment and uses the Ubuntu system environment. By mapping port 8088 to the environment other than the Docker environment, we can access this port on the host machine (development machine). Other configuration details can be Google by ourselves

Create docker/Dockerfile enter the name of the container in the Docker configuration dialog box add port mapping 8088:8088 Add maven command run before build:

	clean package -Dmaven.test.skip = true
Copy the code

When the project is built, the jar typed under Target is automatically copied to the project root directory, which will be used when we publish to Docker.

run

Docker will build the image, configure the container, and then publish the JAR package to the TMP directory of the container. Finally, start the project. You can see the Spring Banner and the associated startup log in the plugin console.

conclusion

That’s all for this installment of Docker deployment of my first SpringBoot project, so give it a try. Please bear with me and I’ll see you next time.