In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you how Docker deploys the SpringBoot project to integrate Redis images to do access counting. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.
The final effect is as follows
Just a few steps.
1. Install Docker CE 2. Run the Redis image 3.Java environment to prepare 4. Project preparation 5. Write Dockerfile 6. Release Project 7. Test service
Environmental preparation
System: Ubuntu 17.04x64
Docker 17.12.0-ce
IP:45.32.31.101
First, install Docker CE
Domestic use is not recommended: "script installation", will download the installation is very slow, use step 1 installation, see the link below: general installation method
1. Conventional installation mode
Ubuntu 17.04 x64 install Docker CE
two。 Script for installation
Scripts are not recommended for domestic installation:
Install Docker CE
Curl-fsSL get.docker.com-o get-docker.sh$ sudo sh get-docker.shIf you would like to use Docker as a non-root user, you should now consideradding your user to the "docker" group with something like: sudo usermod-aG docker your-userRemember that you will have to log out and back in for this to take warning: Adding a user to the "docker" group will grant the ability to run containers which can be used to obtain root privileges on the docker host. Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface for more information.
Verify Docker CE
Verify that Docker CE is installed correctly by running the hello-world image
$sudo docker run hello-worldroot@souyunku:~# sudo docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEhello-world latest f2a91732366c 7 weeks ago 1.85kB
2. Run Redis image
1. Run Mirror
$docker run-- name redis-6379-p 6379Viru 6379-d redisUnable to find image 'redis:latest' locallylatest: Pulling from library/redisc4bb02b17bb4: Pull complete 58638acf67c5: Pull complete f98d108cc38b: Pull complete 83be14fccb07: Pull complete 5d5f41793421: Pull complete ed89ff0d9eb2: Pull complete Digest: sha256:0e773022cd6572a5153e5013afced0f7191652d3cdf9b1c6785eb13f6b2974b1Status: Downloaded newer image for redis:latest2f1f20f672e386a61644e1c08232ea34bdfd6a0c244b55fa833fcfd6dd207288
two。 Check the mirror image
View Mirror
Root@souyunku:~# docker images redisREPOSITORY TAG IMAGE ID CREATED SIZEredis latest 1e70071f4af4 4 weeks ago 107MB
View mirroring process
Root@souyunku:~# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2f1f20f672e3 redis "docker-entrypoint.s..." 14 seconds ago Up 14 seconds 0.0.0.06379/tcp redis-6379 6379-> 6379/tcp redis-6379
View Container process
Root@souyunku:~# docker container psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2f1f20f672e3 redis "docker-entrypoint.s..." 7 minutes ago Up 7 minutes 0.0.0.014 6379-> 6379/tcp redis-6379
3. Test the Redis service
Test and store data by connecting to the Redis service through redis-cli
Root@souyunku:~# docker run-it-- link redis-6379:redis-- rm redis redis-cli-h redis- p 6379redis:6379 > set count 1OKredis:6379 > get count "1" redis:6379 > exitroot@souyunku:~#
III. Java environment preparation
Note: read the following steps!
The 1.Java environment is designed to compile the Github Maven SpringBoot sample project and prepare
two。 Or you can compile and upload it locally, then the following Java environment, installation: Jdk, Maven, Git, can be done without configuration.
1. Install Jdk
Download JDK: 1
To download jdk1.8 in Linux environment, please go to (official website) to download the installation file of jdk
Http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Download JDK: 2
My link on Baidu Cloud disk: http://pan.baidu.com/s/1jIFZF9s password: u4n4
Download JDK: 3
Download using wget
$wget-no-cookies-no-check-certificate-header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz
Note that if you use: download JDK: 3
So in the following steps, replace jdk1.8.0_144 with jdk1.8.0_141
Start installation
Upload to / opt directory
Decompression
$cd / opt$ tar zxvf jdk-8u144-linux-x64.tar.gz$ mv jdk1.8.0_144/ / lib/jvm
Configure environment variables
$vi / etc/profile#jdkexport JAVA_HOME=/lib/jvmexport JRE_HOME=$ {JAVA_HOME} / jre export CLASSPATH=.:$ {JAVA_HOME} / lib:$ {JRE_HOME} / lib export PATH=$ {JAVA_HOME} / bin:$PATH
Make the environment variable effective
$source / etc/profile
Verification
Root@souyunku:~# java-versionjava version "1.8.0mm 141" Java (TM) SE Runtime Environment (build 1.8.0_141-b15) Java HotSpot (TM) 64-Bit Server VM (build 25.141-b15, mixed mode)
two。 Install Maven
$apt-get install maven
Verify Maven
Root@souyunku:~# mvn-vApache Maven 3.3.9Maven home: / usr/share/mavenJava version: 1.8.000141, vendor: Oracle CorporationJava home: / lib/jvm/jreDefault locale: en_US, platform encoding: UTF-8OS name: "linux", version: "4.10.0-35-generic", arch: "amd64", family: "unix"
3. Install Git
$apt-get install git
Verify Maven
Root@souyunku:~# git-- versiongit version 2.11.0
IV. Project preparation
1. Compile the project
1. Compile the project on the server Maven yourself
Clone a project using git
$git clone https://github.com/souyunku/other-projects.git
Compile a project using maven
$cd other-projects/docker-spring-boot-demo/
two。 Modify the project
Modify the Redis server address spring.redis.host=45.32.44.217 to the local IP. When running the Redis image, Redis has been made into a public network service with 0.0.0.0 IP 6379-> 6379/tcp.
$vi src/main/resources/application.properties# Redis server address spring.redis.host=45.32.44.217$ mvn package
Copying the docker-spring-boot-demo-0.0.1-SNAPSHOT.jar project under the target/ directory to the / opt directory will be used later.
$cp target/docker-spring-boot-demo-0.0.1-SNAPSHOT.jar / opt/
two。 Compile the project locally on Maven, then upload it to the / opt directory and use it later.
Modify the Redis server address of application.properties
Other-projects/docker-spring-boot-demo/src/main/resources/application.properties# Redis server address spring.redis.host=45.32.44.217
5. Write Dockerfile
Writing Dockerfile is based on java:8 image
$cd / opt/$ touch Dockerfile$ vi Dockerfile
The edited content is as follows
# based on which image FROM java:8# to mount the local folder to the current container VOLUME / tmp# copy files to the container It can also be written directly as ADD docker-spring-boot-demo-0.0.1-SNAPSHOT.jar / souyunku-app.jarADD docker-spring-boot-demo-0.0.1-SNAPSHOT.jar souyunku-app.jarRUN bash-c 'touch / souyunku-app.jar'# Open 80 port EXPOSE 8 configuration container command ENTRYPOINT executed after startup ["java", "- Djava.security.egd=file:/dev/./urandom", "- jar", "/ souyunku-app.jar"]
VI. Release the project
1. Compile image
$cd / opt/$ docker build-t souyunku-app:v1.
When you see the following message, it proves that your Dockerfile is not wrong, and that the image has been compiled successfully.
Sending build context to Docker daemon 18.72MBStep 1x6: FROM java:88: Pulling from library/java5040bd298390: Pull complete fce5728aad85: Pull complete 76610ec20bf5: Pull complete 60170fec2151: Pull complete e98f73de8f0d: Pull complete 11f7af24ed9c: Pull complete 49e2d6393f32: Pull complete bb9cdec9c7f3: Pull complete Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9dStatus: Downloaded newer image for java:8-> d23bdf5b1b1bStep 2 Lex6: VOLUME / tmp-- > Running in 0559a62b0cd5Removing intermediate container 0559a62b0cd5-> b1f3846913a4Step 3gamble 6: ADD docker-spring-boot-demo-0.0.1-SNAPSHOT.jar souyunku-app. Jar-> 9f60dad5d2acStep 4 touch 6: RUN bash-c 'touch / souyunku-app.jar'-- > Running in 39d5c09ab614Removing intermediate container 39d5c09ab614-- > 2b691adf7922Step 5 78815d6fe6b2Step 6: EXPOSE 80-> Running in 11a577437a23Removing intermediate container 11a577437a23-- > 78815d6fe6b2Step 6 78815d6fe6b2Step 6: ENTRYPOINT ["java" "- Djava.security.egd=file:/dev/./urandom", "- jar", "/ souyunku-app.jar"]-- > Running in eca10fed3d02Removing intermediate container eca10fed3d02-- > 8ec4e85a0f05Successfully built 8ec4e85a0f05Successfully tagged souyunku-app:v1
two。 View Mirror
Root@souyunku:/opt# docker images souyunku-appREPOSITORY TAG IMAGE ID CREATED SIZEsouyunku-app v1 8ec4e85a0f05 2 minutes ago 681MB
3. Run Mirror
The background daemon runs and then maps the container port to public network port 80
Root@souyunku:/opt# docker run-- name MySpringBoot-d-p 80:80 souyunku-app:v1e68d438603619e363883d4eae65d3918e1c3e00f867731207bccf06f5690dc64
4. View the process
Looking at the container process, you can see that redis is on port 6379 and the MySpringBoot project is on port 80.
Root@souyunku:/opt# docker container psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESe68d43860361 souyunku-app:v1 "java-Djava.securit..." About a minute ago Up About a minute 0.0.0.0 docker-entrypoint.s 80-> 80/tcp MySpringBoot0f9646171edd redis "docker-entrypoint.s …" 39 minutes ago Up 39 minutes 0.0.0.0 6379/tcp redis-6379 6379-> 6379/tcp redis-6379
VII. Testing service
Browser access: http://127.0.0.1/, of course I did not enter 127.0.0.1 I did it directly on the server, using the public network IP
Docker Compose
Docker Compose is one of the Docker official orchestration (Orchestration) projects, which is responsible for the rapid deployment of distributed applications in clusters.
An application that uses Docker containers, usually consisting of multiple containers. With Docker Compose, you no longer need to use the shell script to start the container. In the configuration file, all containers are defined by services, and then the docker-compose script is used to start, stop and restart the application, and the services in the application and all dependent containers.
These are all the contents of the article "how to deploy the SpringBoot project to integrate Redis images for access counting". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.