In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Docker how to deploy a java and mysql independent project environment, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can get something.
First of all, I want to package jar into docker. Instead of copying each time, you can also use a folder to define a folder in advance and put the jar package into it. When docker starts, it automatically starts the jar package.
The dockerfile file is required for packaging. Create the Dockerfile configuration in the running directory as follows:
FROM openjdk:8-jdk-alpineENV LANG C.UTF-8RUN apk-- update add ttf-dejavu & &\ rm-rf / var/cache/apk/*MAINTAINER "haolin#189.cn" LABEL description= "suishoupai backend" WORKDIR appADD ruoyi-admin.jar / app/app.jarEXPOSE 8081CMD java-jar / app/app.jar
FROM openjdk:8-jdk-alpine means that the basic image we use is a 8-jdk-alpine package released by openjdk and packaged in alpine linux.
ENV LANG C.UTF-8 means we're going to adopt a UTF-8 environment.
RUN apk-- update add ttf-dejavu & &\ rm-rf / var/cache/apk/*
Is to install the font library and delete the cache installation package, the font library is used to generate CAPTCHA and other functions.
MAINTAINER and LABEL description, please set them by yourself.
The WORKDIR app working directory does not need to be modified.
ADD test-admin.jar / app/app.jar adds the jar package to the image, and if it is a development environment, it can be placed in a directory, just like it is packaged.
CMD java-jar / app/app.jar starts the jar package and sets the startup parameters as needed.
When finished, execute docker build-t username / image name: 1.01. You can complete the image encapsulation.
You can see the finished image package by viewing the image through docker image ls.
After packaging the java image, you need to package the mysql image. First, create the docker-compose.yaml in the running directory.
If you want two docker to share one ip, I think it is clearer to configure through docker-compose. The main idea is to create two service:
An app service uses our java image. If the network mode is set to service:mysql, you can use mysql's network card.
For a mysql service, when using mysql:5.7, you need to note that the default mysql encoding method does not support Chinese. You need to configure it and set the time zone:
Command:
-- character-set-server=utf8mb4
-- collation-server=utf8mb4_general_ci
-- explicit_defaults_for_timestamp=true
-- lower_case_table_names=1
-- max_allowed_packet=128M
-sql-mode= "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
Environment:
TZ: Asia/Shanghai
Then you can choose to configure the database name, root password, and so on.
Finally, map the data directory of mysql to the data directory under the project directory, and publish the ports in app. To visit the outside world.
After the configuration is complete, pass:
Docker-compose up creates a mirror
Start mirroring through docker-compose start
Stop mirroring through docker-compose stop
Docker-compose down deletes the mirror.
After startup, you can view the started services through docker ps, or all services through docker ps-a.
Complete configuration file. As follows:
Version: '3'services: app: container_name: XXXX_app image: haol666/XXXX:1.01 network_mode: "service:mysql" depends_on:-mysql mysql: container_name: mysql:5.7 command:-- character-set-server=utf8mb4-- collation-server=utf8mb4_general_ci-- explicit_defaults_for_timestamp=true-- lower_case_table_names=1-- max_allowed_ Packet=128M-sql-mode= "STRICT_TRANS_TABLES NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO "environment: TZ: Asia/Shanghai MYSQL_DATABASE: XXXX MYSQL_ROOT_PASSWORD: XXXX MYSQL_USER: 'XXXX' MYSQL_PASS:' XXXX' MYSQL_HOST:'% 'volumes: -. / data:/var/lib/mysql ports: -" 8080 TZ 443 "expose: -" 8080 "
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.