Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of packaging and uploading SpringBoot to docker and implementing multi-instance deployment

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the method of packaging and uploading SpringBoot to docker and implementing multi-instance deployment. The content is clear. Interested partners can learn about it. I believe it will be helpful after reading it.

Recently, a friend asked me if I had ever played docker, and the answer was not very strong ^-^ (when I first played cloud, I played for a while, but later I seldom used it in actual development, so I basically forgot.), I spent some time today to sort out my previous notes and go through a process, so record it. C V will be fine when I play next time.

1. Install Docker and enable remote access

1.1 installation

# check the kernel version of the virtual machine. It must be 3.10 or above. Uname-r # install dockeryum install docker# enter y to confirm installation # start dockersystemctl start docker# to view docker version docker-v # Boot dockersystemctl enable docker# stop dockersystemctl stop docker# restart dockersystemctl restart docker

1.2 enable remote access

Modify the file docker.service

Vim / usr/lib/systemd/system/docker.service

Modify the ExecStart line

# ExecStart=/usr/bin/dockerd-H fd://-containerd=/run/containerd/containerd.sock

ExecStart=/usr/bin/dockerd-H tcp://0.0.0.0:2375-H unix:///var/run/docker.sock

# reload configuration file systemctl daemon-reload # restart service systemctl restart docker.service # check whether the port is enabled (if it is a server such as Ali Cloud, you need to "Security"-> "Firewall" to open port 2375) netstat-nlpt# to check whether the curl http://127.0.0.1:2375/info is in effect

2. IDEA installs the docker plug-in and connects

2.1 install the plug-in

This is very simple, just take a screenshot step by step. (who is this, how to use the Chinese IDEA ~)

2.2 Connect docker

3. Pack jar and write Dockerfile and jar. I won't repeat this here. Write a Dockerfile, pay attention to the underlining, and then modify it.

FROM java:8# maintainer information MAINTAINER houyu# the / tmp directory here will be automatically mounted as anonymous volumes at run time, and any information written to / tmp will not be recorded in the container storage layer VOLUME / tmp# replication context directory, / build/libs/fastboot-0.0.1.jar will be executed in the container COPY / build/libs/fastboot-0.0.1.jar fastboot-0.0.1.jar# bash Make fastboot-0.0.1.jar accessible to # RUN to create a new layer, execute these commands on it, and after execution, the changes in the commit layer form a new mirror. RUN bash-c "touch / fastboot-0.0.1.jar" # specify time zone # ENV TZ='Asia/Shanghai'# states that the runtime container provides a service port, which is just a declaration The service EXPOSE 1000 will not open this port at run time because of this declaration. Specify container launcher and parameters "" ENTRYPOINT ["java", "- jar", "fastboot-0.0.1.jar", "--spring.profiles.active=prod"]

4. IDEA configuration build image

4.1 configure run script

4.2 run the script

5. The host views the image and confirms that the deployment is successful

6. Deploy multiple instances

The specific commands are followed:

Operation script

# View Image docker images# View installation Container docker ps-a # Clone c1726e8f3819 Image installed as a fb1.2 Container #-d: run in the background #-p: map the port of the host to a port of the container host port: the port inside the container docker run-- name fb1.2-d-p 10008c1726e8f3819 10007 c1726e8f3819 # View the installed container docker ps-a # View Operation Container docker ps # validates fb1.1curl 127.0.0.1 fb1.2curl 10007 # verifies fb1.2curl 127.0.0.1 Vol 10008

Commonly used docker commands (private wine)

1), mirror operation (https://hub.docker.com/)

1. Retrieve the details of the image, such as the TAG of the image.

Docker search image keywords such as: docker search redis

2. Pull the mirror image (: tag is optional, tag represents the label, mostly the version of the software, the default is latest)

Docker pull registry.docker-cn.com/library/redis:5.0.3 accelerated pull

Docker pull acceleration address + image name: tag, such as docker pull redis:5.0.3

3. View all local images

Docker images

4. Delete the specified local image

Docker rmi image Id or name such as: docker rmi Tomcat

5. Rename the image

Docker tag IMAGEID (Image id) REPOSITORY:TAG (Repository: tag)

2), container operation (software image-run image-generate a container)

1. Search for images

Docker search tomcat

2. Pull the mirror image (: tag is optional, tag represents the label, mostly the version of the software, the default is latest)

Docker pull tomcat:latest

3. Launch the container according to the image (latest can be omitted and other tags must be added)

-d: running in the background

-p: map the port of the host to a port of the container: the port inside the container

Docker run-- name alias-d host port: the port inside the container REPOSITORY/IMAGE ID

For example, docker run-- name mytomcat-d 8080 tomcat:latest

3.1 restart the container

Docker restart container name / ID

4. View the containers in operation

Docker ps

5. View all installed containers

Docker ps-a

6. Stop the container in operation

The id/ name of the docker stop container

7. Start the container

The id/ name of the docker start container

8. Delete a container

The id/ name of the docker rm container

9. View the container log

Docker logs container-name/container-id (container name or container ID)

10. Enter the specified container space

Docker exec-it container name / ID / bin/bash

For example: docker exec-it tensquare_es / bin/bash

7. For security issues, please do not enable docker remote access in the online environment, otherwise it may be regarded as a meat machine.

After reading the above content, do you have a better understanding of the method of packaging and uploading SpringBoot to docker and realizing multi-instance deployment? if you want to learn more, please follow 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report