Pre-preparation:
list:
- Linux with docker installed
- The jar file packaged by springboot (this project has only one return "hello world" interface)
Linux IP address: 192.168.221.129
The interface of the springboot project:
1. Upload the jar file to Linux
The location I uploaded is: /root/dockerJar, as follows:
2. Docker downloads the jdk8 image
docker pull java:8
View images using docker images :
3. Deploy the project by mounting the directory
Principle: When we run the jdk image, we mount the jar file in Linux to the image, and as the image runs, the project is also executed
Excuting an order:
docker run -d -p 8080:8080 --name helloworld-2 -v /root/dockerJar/helloworld-0.0.1-SNAPSHOT.jar:/root/app.jar java:8 java -jar /root/app.jar
explain:
docker run: the command to run the image
-d: Indicates the way to start and run in the background
helloworld-2: Indicates the name of the container generated after the image is run
-p 8080:8080: Mapping the 8080 port of the Linux host to communicate with the 8080 port in the docker container
-v /root/dockerJar/helloworld-0.0.1-SNAPSHOT.jar:/root/app.jar: -v indicates that the directory is mounted, which means that /root/dockerJar/helloworld-0.0.1-SNAPSHOT.jar outside Linux The file, corresponding to /root/app.jar in the docker container, is regarded as the same file
java:8: The name of the image we downloaded
java -jar /root/app.jar: Indicates the command executed in docker, which is used to start the jar program
After the execution is completed, it is as follows:
4. Access the project
Note: You need to close the Linux firewall or open port 8080, otherwise the access will fail
Open firewall:
systemctl stop firewalld
Use a browser to access:
http://192.168.221.129:8080/test
The result is as follows: