Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

Integration steps (Maven + SpringBoot)

1. Add configurations in maven’s POM. XML file

	<properties>
		<docker.image.prefix>xd</docker.image.prefix>
	</properties>
	
	<build>
		<finalName>docker-demo</finalName>
	    <plugins>
	        <plugin>
	            <groupId>com.spotify</groupId>
	            <artifactId>dockerfile-maven-plugin</artifactId>
	            <version>1.3.6</version>
	            <configuration>
	                <repository>${docker.image.prefix}/${project.artifactId}</repository>
	                <buildArgs>
	                    <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
	                </buildArgs>
	            </configuration>
	        </plugin>
	    </plugins>
	</build>
Copy the code

The configuration on

Spotify docker-Maven-plugin uses maven plugin to build docker image. Project.build. finalName∗∗ name of outputs, the default is ∗∗{project.build.finalname}** Name of outputs, the default is ** project.build.finalname ∗∗ name of outputs, Default is ∗ ∗ {project. ArtifactId} – ${project. Version}

2. Package the SpringCloud image and upload it to a private repository and deploy it

What is a dockerFile

What is a Dockerfile: a script made up of a series of commands and parameters that are applied to the underlying image, eventually creating a new image

Create Dockerfile add content (the default is the root directory, you can modify for SRC/main/docker/Dockerfile, if need to develop path)

Here is the contents of the dockfile:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java"."-jar"."/app.jar"]
Copy the code

Parameter explanation:

  • FROM : Requires a base image, either public or private, on which future builds will be based. If multiple images are created in the same Dockerfile, multiple FROM directives can be used

  • A temporary file is created in the /var/lib/docker directory of the host and linked to/TMP of the container. The modification step is optional and necessary if file system applications are involved. The/TMP directory is used to persist to the Docker data folder because the embedded Tomcat container used by Spring Boot uses/TMP as the working directory by default

  • ARG: sets the parameter added when compiling the image. ENV is the environment variable used to set the container

  • COPY: Only supports copying local files to containers. ADD is more powerful but more complex

  • ENTRYPOINT: command executed when the container is started

  • EXPOSE 8080: Exposes the mirror port

3. Build an image

mvn install dockerfile:build
mvn install dockerfile:build -Dmaven.test.skip=true
Copy the code

Ps: How to package Linux on Ali Cloud

4. Add the configuration in the Setting file of the Maven installation directory

<server>
	<id>docker-registry</id>
	<username>* * * * * * *</username>
	<password>* * * * * *</password>
</server>
Copy the code

5. Modify aliyun Centeros7 Docker configuration to open remote access

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

ExecStart this line followed by -h TCP: / / 0.0.0.0:2375 – H Unix: / / / var/run/docker. The sock

End result:

ExecStart = / usr/bin/dockerd -h TCP: / / 0.0.0.0:2375 - H Unix: / / / var/run/docker. The sockCopy the code

6. Restart

systemctl daemon-reload

systemctl start docker
Copy the code

7. The server checks whether the listener starts

Netstat anp | grep 2375 curl 127.0.0.1:2375 / infoCopy the code

8. Create a vm in Windows environment variablesDOCKER_HOSTAnd has a value ofTCP ://[change to your remote server port number]:2375

9. Playing tag

docker tag a1b9fc71720d registry.cn-shenzhen.aliyuncs.com/xd/xd_images:docker-demo-v201808
Copy the code

10. Push it to the mirror vault

docker push registry.cn-shenzhen.aliyuncs.com/xd/xd_images:docker-demo-v201808
Copy the code

11. The application server pulls the image

docker pull registry.cn-shenzhen.aliyuncs.com/xd/xd_images:docker-demo-v201808
Copy the code

12. Start

docker run -d --name xd_docker_demo1 -p 8099:8080  a1b9fc71720d
Copy the code

13. View startup logs

docker logs -f  containerid
Copy the code

14. Access

http://[IP]:8099/find/user
Copy the code

Docker integration registry

1. Add maven plug-in

<properties>
  <docker.image.prefix>xd</docker.image.prefix>
</properties>
<build>
  <finalName>docker-demo</finalName>
  <plugins>
    <plugin>
      <groupId>com.spotify</groupId>
      <artifactId>dockerfile-maven-plugin</artifactId>
      <version>1.3.6</version>
      <configuration>
        <repository>${docker.image.prefix}/${project.artifactId}</repository>
        <buildArgs>
          <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
        </buildArgs>
      </configuration>
    </plugin>
  </plugins>
</build>
Copy the code

2. New Dockerfile

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Copy the code

Pack 3.

mvn install dockerfile:build
mvn install -Dmaven.test.skip=true dockerfile:build
Copy the code

4. Push ali Cloud mirror warehouse

Ali cloud image warehouse: dev.aliyun.com/search.html

docker tag 062d2ddf272a registry.cn-shenzhen.aliyuncs.com/xd/xd_images:eureka-v20180825
docker push registry.cn-shenzhen.aliyuncs.com/xd/xd_images:eureka-v20180825
docker pull registry.cn-shenzhen.aliyuncs.com/xd/xd_images:eureka-v20180825
Copy the code

5. View logs

docker logs -f  containerid
Copy the code

6. Run

docker run -d --name docker-eureka-server -p 8761:8761 e7f687f101a7

Docker Redis installation

1. Search for mirrors

docker search redis
Copy the code

2. Pull

docker pull docker.io/redis
Copy the code

3. Start

docker run --name "xd_redis" -p 6379:6379 -d 4e8db158f18d
Copy the code

Reference:

docker run --name "xd_redis" -p 6379:6379 -d 4e8db158f18d --requirepass "123456" -v $PWD/data:/data
Copy the code

4. Access the Redis container and perform operations

docker exec -it 295058d2b92e redis-cli
Copy the code