Docker_ use basis

Benefits of 1 docker

Out of the box; rapid deployment; portability; isolated from the environment

2 docker common commands

View existing system image

docker images

Web search mirror (mirror name composed repository: tag)

docker search image name

Pull downloaded to the local mirror (mirror Name Composition repository: tag)

docker pull image name

Remove the mirror (-f forced to delete)

docker rmi -f image id

Run (-d represented daemon running in the background; -p port mapping represents, represents a container port behind, in front of the machine showing a physical port, the physical port unit can not be repeated) (Name mirror composed repository: tag)

When the mirror is not present locally, the command will automatically pull the mirror from the network to the local

docker run -d -p physical machine interface: a container port mirroring --name name "specified container Name"

View the currently running container

docker ps

View container inside information

docker inspect the container or containers id Name

Stop the container

docker stop container or containers id Name

Start container

docker start container name names

Access: access time or access port configured in accordance with a physical machine.

 

3 image uploaded to the warehouse

Mirrored storage warehouse is divided into private and public.

1) Upload the public's image.

Create a mirror warehouse on Ali cloud (https://www.alibabacloud.com/help/zh/doc-detail/63591.htm)

Creating a warehouse through the interface when there will be options, click on the public

Log in warehouses created on Ali cloud on the local server requires a password (Ali cloud official website tutorial manual)

Then hit version, upload

docker tag image id Warehouse Address: [image version number] 
Docker mirroring the Push id Warehouse Address: [image version number]

Direct pull mirroring

 

2) Upload private images.

Create a mirror warehouse on Ali cloud (https://www.alibabacloud.com/help/zh/doc-detail/63591.htm)

Creating a warehouse through the interface when there will be options, click on the private

Log in warehouses created on Ali cloud on the local server requires a password (Ali cloud official website tutorial manual)

Then hit version, upload

docker tag Warehouse Address: [image version number] 
Docker the Push Warehouse Address: [image version number]

Log in warehouses created on Ali cloud on the local server requires a password (Ali cloud official website tutorial manual), then pull the mirror

 

Automated Deployment mirror 4 Jenkins (continuous build mirrored -> pull Mirror -> Run)

 

5 Docker image built with Maven

Use docker's maven plugin application to build springboot

docker's maven plugin can be springboot packaged into a mirror, so an application made to the Mirror There are a lot of ways, this is the docker's function, we can introduce maven plugin docker in IDEA is directly packaged as a mirror, can also direct non project after the docker's maven package on linux, command docker be mirrored.

Official website describes as follows

https://spring.io/guides/gs/spring-boot-docker/

1) add a simple application springboot

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DockerDemoApplication {

    @RequestMapping
    public String home() {
        return "Hello Docker World";
    }

    public static void main(String[] args) {
        SpringApplication.run(DockerDemoApplication.class, args);
    }

}

 

2)   Go to localhost: 8080 to see if your "Hello Docker World" message.

3)  create a Dockerfile in our Spring Boot project

dockerfile script is composed of a series of commands and parameters, these commands are applied to the base image, and ultimately create a new image.

Dockerfile create a file, right-project in the root directory of the project, click Create.

Enter the following

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

from command: the need for a base image that openjdk, version 8-jdk-alpine (springboot start the application of the most basic needs of java environment)

volume command: persistent dcker working directory play / tmp directory

arg command: Join us after the package jar package that corresponds to written jar_file label pom file.

copy: Copy files to the local container docker

entrypoint: command required when starting a container

Other specific parameters can be Baidu dockerfile view other parameters.

 

3) Add the maven configuration

<properties>
   <docker.image.prefix>sunru</docker.image.prefix>
</properties>
<build>
<finalName>demon_docker</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>

 

4) Construction of the mirror

执行 mvn install dockerfile:build

There docker need local environment, otherwise it will fail to build.

Then 3 image uploaded to the repository mirroring upload

Guess you like

Origin www.cnblogs.com/S-Mustard/p/11373311.html