A brief analysis of SpringBoot packaging and uploading to docker and implementing multi-instance deployment (IDEA version)

A brief analysis of SpringBoot packaging and uploading to docker and implementing multi-instance deployment (IDEA version)

Recently a friend asked me if I have ever played with Docker. I was not very confident to answer ^ - ^ (I came into contact with it when I first started playing with cloud, played with it for a while, and then rarely used it in actual development, so I basically forgot it.), today I spent some time organizing my previous notes and organizing a process, I'll record it, so that I can CV next time I play with it~

1. Install Docker and enable remote access

1.1 Installation

# Check the virtual machine kernel version, which must be 3.10 or above uname -r
# Install Docker
yum install docker
# Enter y to confirm the installation# Start Docker
systemctl start docker
# Check the docker version docker -v
# Start Docker on boot
systemctl enable docker
# Stop Docker
systemctl stop docker
# Restart Docker
systemctl 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 the configuration file systemctl daemon-reload 
# Restart the service systemctl restart docker.service 
# Check whether the port is open (if it is a server such as Alibaba Cloud, you need to open port 2375 in "Security" -> "Firewall")
netstat -nlpt
# Check whether it is effective curl http://127.0.0.1:2375/info

2. IDEA installs the docker plug-in and connects

2.1 Installing plugins

This is very simple, I just took screenshots step by step. . . (Who is this? How do I use the Chinese version of IDEA?)

insert image description here

2.2 Connect to Docker

insert image description here

3. Pack the jar package and write the Dockerfile. Packing the jar package will not be described here. . . Write Dockerfile, pay attention to the underlined parts, and then modify them

insert image description here

FROM java:8
# Maintainer information MAINTAINER houyu
# The /tmp directory here will be automatically mounted as an anonymous volume at runtime, and any information written to /tmp will not be recorded in the container storage layer VOLUME /tmp
# Copy /build/libs/fastboot-0.0.1.jar in the context directory to the container COPY /build/libs/fastboot-0.0.1.jar fastboot-0.0.1.jar
# Run in bash mode to make fastboot-0.0.1.jar accessible. # RUN Create a new layer and execute these commands on it. After the execution is completed, commit the changes to this layer to form a new image.
RUN bash -c "touch /fastboot-0.0.1.jar"
# Specify the time zone # ENV TZ='Asia/Shanghai'
#Declare the service port provided by the runtime container. This is just a declaration. The application will not open the service of this port at runtime because of this declaration. EXPOSE 10007
#Specify the container startup program and parameters <ENTRYPOINT> "<CMD>"
ENTRYPOINT ["java","-jar","fastboot-0.0.1.jar", "--spring.profiles.active=prod"]

4. IDEA configuration build image

4.1 Configure the run script

insert image description here

4.2 Run the script

insert image description here

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

insert image description here

6. Deploy multiple instances

The specific commands are as follows:

insert image description here

Operation Script

# View docker images
# View the installed container docker ps -a
# Clone the c1726e8f3819 image and install it as a fb1.2 container # -d: Run in the background # -p: Map the host port to a port in the container Host port: Port inside the container docker run --name fb1.2 -d -p 10008:10007 c1726e8f3819 
# View the installed container docker ps -a 
# View the running container docker ps 
# Verify fb1.1
curl 127.0.0.1:10007 
# Verify fb1.2
curl 127.0.0.1:10008

Commonly used docker commands (private wine)

1) Image operation (https://hub.docker.com/)

1. Retrieve detailed information about the image, such as the image's tag.
docker search image keyword such as: docker search redis
2. Pull the image (:tag is optional, tag means label, mostly the version of the software, the default is latest)
docker pull registry.docker-cn.com/library/redis:5.0.3 to speed up the 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 (warehouse: tag)

2) Container operation (software image ---- running image ---- generating a container)

1. Search for images
docker search tomcat
2. Pull the image (:tag is optional, tag means label, mostly the version of the software, the default is latest)
docker pull tomcat:latest
3. Start the container according to the image (latest can be omitted, other tags must be added)
-d: Run in the background
-p: Map the host port to a port in the container Host port: the port inside the container
docker run --name alias -d host port: port inside the container REPOSITORY/IMAGE ID
For example: docker run --name mytomcat -d 8080:8080 tomcat:latest
3.1 Restarting the container
docker restart container name/ID
4. View the running container
docker ps
5. View all installed containers
docker ps -a
6. Stop the running container
docker stop container id/name
7. Start the container
docker start container id/name
8. Delete a container
docker rm container id/name
9. View the container log
docker logs container-name/container-id (container name or container ID)
10. Enter the designated 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 treated as a meat machine

For details, please read How to solve the problem of server being attacked due to Docker exposing port 2375!

This is the end of this article about briefly analyzing SpringBoot packaging and uploading to docker and realizing multi-instance deployment (IDEA version). For more related spring boot packaging and uploading to docker content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to package the project into docker through idea
  • idea combines docker to realize image packaging and one-click deployment
  • How to integrate Docker into IDEA to achieve packaging

<<:  js realizes shopping cart addition and subtraction and price calculation functions

>>:  Example analysis of mysql stored procedures that trigger error conditions in stored procedures (SIGNAL and RESIGNAL statements)

Recommend

What scenarios are not suitable for JS arrow functions?

Table of contents Overview Defining methods on an...

Introduction to possible problems after installing Tomcat

1. Tomcat service is not open Enter localhost:808...

MySQL Practical Experience of Using Insert Statement

Table of contents 1. Several syntaxes of Insert 1...

ReactJs Basics Tutorial - Essential Edition

Table of contents 1. Introduction to ReactJS 2. U...

Installing Windows Server 2008 operating system on a virtual machine

This article introduces the installation of Windo...

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL Environment Construction Tutorial

Preparation 1. Environmental Description: Operati...

jQuery achieves seamless scrolling of tables

This article example shares the specific code of ...

Detailed explanation of Truncate usage in MySQL

Preface: When we want to clear a table, we often ...

How to use Docker plugin to remotely deploy projects to cloud servers in IDEA

1. Open port 2375 Edit docker.service vim /lib/sy...

A brief discussion on MySQL user permission table

MySQL will automatically create a database named ...

How to build a MySQL PXC cluster

Table of contents 1. Introduction to PXC 1.1 Intr...

Implementation of Nginx configuration of multi-port and multi-domain name access

To deploy multiple sites on a server, you need to...

mysql join query (left join, right join, inner join)

1. Common connections for mysql INNER JOIN (inner...

Some conclusions on the design of portal website focus pictures

Focus images are a way of presenting content that ...

Summary of H5 wake-up APP implementation methods and points for attention

Table of contents Preface Jump to APP method URL ...