Deploy the Docker image to Rancher global configuration using xxl-job-admin as an example

The process takes xxl-job-admin as an example

1. Basic environment

  • win/mac/linux
  • Rancher
  • Docker

2. Download source code


Download xxl-job xxl-jobGithub xxl-job official address from Github

3. Modify the source code

Openxxl-jobdownxxl-job-admin
Please add image description
Reviseapplication-propertiesdocument

Modify database

Change it to this format: Surrounded by braces

${xxx:yyy}

This form can be read from the environment variable according to the xxx name.
If the xxx name cannot be read, use the yyy
yyy default configuration.
If xxx is followed, we will import it from Rancher.

### xxl-job, datasource
spring.datasource.url=${MYSQL_URL:jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai}
spring.datasource.username=${MYSQL_USERNAME:root}
spring.datasource.password=${MYSQL_PASSWORD:123456}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

Modify Token

### xxl-job, access token
xxl.job.accessToken=${ACCESS_TOKEN:default_token}

All parameters that you want to control externally can be passed in like this

4.Package the image

Pass the current projectMavenPackaged into jar package

(You can also write your own Dockerfile if it comes with the project)

FROM openjdk:8-jre-slim
MAINTAINER xuxueli

ENV PARAMS=""

ENV TZ=PRC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ADD target/xxl-job-admin-*.jar /xxl-job-admin.jar

ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /xxl-job-admin.jar $PARAMS"]

Packaged into a mirror,
the meaning of the parameters will not be explained here.

 docker build -t 172.16.1.77/alibaba/xxl-job-admin:2.4.0 .

Push image

docker push 172.16.1.77/alibaba/xxl-job-admin:2.4.0

5.Rancher configuration

Please add image description
Click on the upper right cornerDepoly

Modify to the following configuration
Please add image description
to start the image into Rancher

  • You can write the name by yourself
  • WorkloadType Scalable refers to dynamic scalability. Two services are started here.
  • Docker Images is the address of the image
  • Port Mapping needs to expose the 8080 internal port (publish the container port) to the external random port (on listening port)
  • Environment Variables is the ${xxx:yyy} part in application-properties just now. Be careful not to write the wrong configuration.

Start effect

Please add image description

Guess you like

Origin blog.csdn.net/w776341482/article/details/128850991