springboot project entry level docker packaging mirror publishing and installation

The springboot project database is mysql, the cache is redis, both MySQL and redis run in the docker environment, and the boot project relies on jdk8 to publish and run in separate containers, so there are many scenarios. This paper uses the simplest way to package and run in jar (note the code in the red section below).

First, the pom configuration is as follows

        <relativePath /> <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot</description>

Secondly, if the project uses application.properties, application.yml to configure multiple environments, we use yml's configuration


#Configure the reading environment
    active: docker

application-docker.yml modification reason, because instead of exposing the container's mysql, redis ports to connect out, it uses the alias of docker--link, so modify the alias to modify the link address host, column

#==========redis configuration information===========#
    host: shuogesha-redis
    port: 6379
      max-active: 8
      max-wait: 1
      max-idle: 8
      min-idle: 0
    timeout: 0

Configure the steps above to package the project pom file directly into jar

clean package -Dmaven.test.skip=true

A Dockerfile needs to be written to produce a mirror of the docker

# Docker image for base2020 run
# VERSION 0.0.1
# Author: shuogesha
# Basic mirror using java
FROM java:8
# author
MAINTAINER shuogesha <2596310607@qq.com>
# VOLUME specifies the temporary file directory as/data.
ARG workdir=/data
VOLUME ${workdir}
WORKDIR ${workdir}
# Add the jar package to the container and rename it app.jar
ADD target/base2020-0.0.1-SNAPSHOT.jar /app.jar
# Specify port 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Then command under the project's root directory, cd to the project's root directory

You can specify the version number by executing the mirror generation command, but now the test just ignores it and pays attention to the following.Number is indispensable

Package the project and set a version number, then see if the comparison was successful
docker build -t shuogesha/base2020 .

After successful packaging, you can run docker images to see if they are successful

Step by step, no flaws, then start running the command, of course you can expose port 8080, or map the local directory to the container, for example, some picture uploads need to be saved all the time to avoid data loss after the container restarts;

docker run -d --name  base2020 --link redis5.0.5:shuogesha-redis  --link mysql5.6:shuogesha-mysql -v /Users/zhaohaiyuan/Downloads/docker/base2020:/data -p 8080:8080 shuogesha/base2020

You can then see if the container is running

docker container ls -a

If the container fails to start or succeeds, you can view the container's log through the container's id

docker logs -f -t container id

Five original articles published, 0% praised, 358 visits
Private letter follow

Tags: Docker Redis MySQL Spring

Posted on Wed, 05 Feb 2020 22:05:38 -0500 by th3void