SpringBoot deployment docker packaged mirror

SpringBoot deployment docker packaged mirror

surroundings:

  1, coding tools: IDEA

  2, packing: maven

  3、docker

  4、linux

  7, JDK1.8

  8、Xshell

  9、Xftp

The first step: Use the idea to create a simple project springboot

  Others cited an article: https://blog.csdn.net/u013777094/article/details/78580710/

Step Two: Setting items generating jar package (both)

  1, modify the pom file

Copy the code
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>ordinary</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>ordinary</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
Copy the code

  2, or you may select the jar and war when generating the project

The third step: Use maven generate package (using the idea without direct command interface operation can (if Maven set no problem you can directly generate the log file directory package will prompt generation))

 

Step four: docker concept

  1, docker: the first is dotCloud company produced a set of container management tool, but then Docker fire up slowly, and even company names are changed Docker from dotCloud.

  2, dockerfile: it Docker image description file, as will be appreciated rocket Step A, B, C, D ......'s.

  3, docker Mirror: by Dockerfile to do it, including the base operating system files and software operating environment, which uses hierarchical storage.

  4, docker container: the mirror is up and running, simple to understand, Docker mirror equivalent program, container equivalent process.

Step four: dockerfile instruction

  Dockerfile composed of a plurality of instructions, each instruction execution programs corresponding to complete certain functions build images, composed by a command + parameter, separated by commas, as comment # start character, although the instruction is not case sensitive, but generally instruction use a little bigger, use lowercase parameters

Step five: dockerfile file example (I simply will springboot project generated image docker no extra configuration)

TODO: a place to point to note is that there is no file suffix dockerfile

Copy the code
# Pull base image  
FROM  java:8  
  
MAINTAINER yihj "[email protected]"
  
VOLUME /tmp
  
# Add to 
ADD ordinary.jar app.jar
RUN bash -c 'touch /app.jar'
  

# Define default command. 
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

# Set the time zone
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
Copy the code

Step Six: The dockerfile jar file and generate a good tool to use ftp upload to linux server just to find a folder under the jar and put in the same directory dockerfile

Step 7: Use docker build -t ordinary: v1.0.

  ALL:

    1, the final surface of the representatives of looking dockerfile file in the current directory

    2, ordinary mirror name

    3, v1.0 version

Step eight: Check the mirror and start

  1, the use of docker images to view the generated image

  2, docker create to create a container docker run to create and run a container

  3, can also be used docker logs container name --tail 100 -f to see the start of the project log to see whether the project start

  3, if all the above steps can be called normal IP ports to add direct access project

Guess you like

Origin www.cnblogs.com/zmsn/p/11697575.html
Recommended