In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how docker deploys SpringBoot and replaces jar packages". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to deploy SpringBoot and replace jar packages with docker".
Engineering catalogue
Dockerfile file
Create a dockerfile file, which will be used later.
File deployment
Create a new / data/docker/hellolearn folder on the server (the file path is customizable), and copy the maven packaged jar package and the dockerfile file created above to the server's new folder (/ data/docker/hellolearn).
Generate a mirror image
Docker build-t hellolearn.
Docker build-t image name: the relative position of the label dockerfile. The period represents the current directory. If you do not write tag, the default is latest.
Start the container
Docker run-d-p 8301 docker run-- name hellolearn hellolearn
Docker start hellolearn
The-d parameter is to let the container run in the background;-- name is to specify the name of the container;-p is to do port mapping, so port 8301 (port before colon) in the server is mapped to port 8301 (port after colon) in container (application.properties is configured with 8301)
Visit web
Jar package mapping deployment
Following the steps above is enough to easily deal with the whole process of docker deploying springboot. But after starting the container, every time you need to update the jar package, you have to remake the image and then the container. The process is tedious and inefficient. So how do you update the jar package directly to complete the deployment without updating the image or container?
5.1 Update dockerfile
The last line entrypoint ["java", "- jar", "/ data/learn-web-0.0.1-snapshot.jar"] runs the learn-web-0.0.1-snapshot.jar file in the / data directory in the container.
5.2 use the docker build command to build an image
Docker build-t hellolearn.
5.3 create & start the container
Docker run-- name hellolearn-it-v / data/docker/newhellolearn/package:/data-d-p 8301 it 8301 hellolearn
-v Host directory is associated with container directory. This maps the / data/docker/newhellolearn/package directory of the host to the / data directory of docker.
In this way, when the jar package changes, you can directly update the jar package in the / data/docker/newhellolearn/package directory of the host. After updating the jar package, you need to restart the container.
Script deployment
The deployment of jar packages causes a problem if the jar package name changes, such as a version number change (learn-web-0.0.1-snapshot.jar-- > > learn-web-1.0.1-snapshot.jar). What do you need to do with it? The third way to deploy through scripting is described below.
6.1 create a hellolearn.sh file
Java-jar / data/learn-web-0.0.1-snapshot.jar
Upload hellolearn.sh to / data/docker/hellolearn/scriptdeploy/package, this folder path can be customized, remember this folder path, you will need it later.
6.2 add script execution permissions
Chmod + x hellolearn.sh
6.3 create dockerfile
Cmd ["sh", "- c", "/ data/hellolearn.sh"] means to start the hellolearn.sh script created in 6.1 when the container starts.
Note that the last command above is entrypoint, which has been changed to cmd in the script deployment. You can learn about the specific differences between entrypoint and cmd if you are interested.
6.4 upload jar package
Put the jar package in the same folder directory of hellolearn.sh, namely / data/docker/hellolearn/scriptdeploy/package, and map this directory (host directory) to the container's / data directory when you create the container.
6.5 File directory structure diagram
The directory structure here does not know if everyone is dizzy. Upload a directory structure map of my host, which is clear at a glance.
6.6 create a mirror
Docker build-t hellolearn-script.
The period at the end represents the current directory, so the command to generate the image needs to be executed in the directory where the dockerfile is located.
6.7 create & start the container
Docker run-- name hellolearn-script-it-v / data/docker/hellolearn/scriptdeploy/package:/data-d-p 8302 it 8301 hellolearn-script
Docker start hellolearn-script
Associate the / data/docker/hellolearn/scriptdeploy/package directory of the host with the container's / data directory mapping. In this way, when the jar package changes, you can directly update the jar package in the host directory. Even if the name of the jar package changes, the hellolearn.sh script needs to be updated. Restart the container after update.
6.8 web test effect
View docker Log
Docker logs [options] container id
Options description:
-f: trace log output
-- since: displays all logs at a certain start time
-t: displays the timestamp
-- tail: only the latest n container logs are listed
7.1 View the log after the specified time and display only the last 100 lines:
Docker logs-f-t-since= "2020-10-01"-tail=100 container id
7.2 check the logs for a specified time period
Docker logs-t-since= "2020-10-01t19:00:00"-- until "2020-10-01t19:00:00" container id
7.3 View the logs after the specified time:
Docker logs-t-since= "2020-10-01t19:00:00" container id
7.4 View the log for the last 5 minutes:
Docker logs-- since 5m container id
7.5 bash the specified container with the exec command:
Docker exec hellolearn-it / bin/bash or docker exec-it hellolearn bash
7.6 View docker ip
Docker inspect-- format=' {{.networksettings.ipaddress}} 'hellolearn
Problems encountered
Problem description: error response from daemon: driver failed programming external connectivity on endpoint flamboyant_leavitt (iptables failed: iptables-- wait-t nat-a docker-p tcp-d 0 dnat 0-- dport 8301-j dnat-- to-destination 172.17.0.2 docker0 8301!-I docker0: iptables: no chain/target/match by that name.
Solution: restart docker. Systemctl restart docker
At this point, I believe you have a deeper understanding of "how docker deploys SpringBoot and replaces jar packages". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.