How to install docker under centos and remotely publish docker in springboot

How to install docker under centos and remotely publish docker in springboot

1. Installation of JDK1.8 under CentOS7.0

(1) Download jdk-8u291-linux-i586.tar.gz from Oracle official website. (2) Uninstall the system's own java

java -version
rpm -qa | grep java
yum -y remove [the above found contents, multiple separated by spaces]

(3) Install JDK

mkdir /usr/java
cd /usr/java
tar -zxvf jdk-8u291-linux-i586.tar.gz

(4) Configure environment variables

vim /etc/profile

Add the following content

export JAVA_HOME=/usr/java/jdk1.8.0_291
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Make environment variables effective

source /etc/profile

test

java -version

2. Installation of Docker

(1) Check the kernel version (Docker requires a 64-bit version and a kernel version above 3.10. If the version is lower than 3.10, you need to upgrade the kernel)

uname -r 

insert image description here

(2) Update the yum package:

yum update -y

(3) Add the Alibaba Cloud yum repository:

cd /etc/yum.repos.d/
wget "http://mirrors.aliyun.com/repo/Centos-7.repo"
mv CentOS-Base.repo CentOS-Base.repo.bak
mv Centos-7.repo CentOS-Base.repo

Execute the update command of the yum source

yum clean all
yum makecache
yum update

(4) Install Docker

yum install -y docker-ce

(5) Start Docker
Start, view information

systemctl start docker
docker info 

[External link image transfer failed, the source site may have an anti-hotlink mechanism, it is recommended to save the image and upload it directly (img-H5LW4OhZ-1619537409080)(imgclip_1.png "imgclip_1.png")]

You can set the startup item later

systemctl enable docker

(6) Configure Docker remote access to execute command editing files

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

Find this line

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

Append

-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

Restart the service

service docker restart

If the prompt file needs to be reloaded, execute

systemctl daemon-reload 

insert image description here

Remote access testing

http://192.168.2.200:2375/version

insert image description here

3.Docker uses the Maven plugin to build and upload images

(1) Create a new Dockerfile

Add a new folder docker under the project's /src/main, and create a Dockerfile file in the folder. The content of the file is as follows

# Based on which image FROM java:8
# Mount the local folder to the current container VOLUME /tmp
# Copy the file to the container, swaggertest-0.0.1-SNAPSHOT.jar here is the name after Maven packaging ADD swaggertest-0.0.1-SNAPSHOT.jar swaggertest.jar
RUN bash -c 'touch /swaggertest.jar'
# Configure the command to be executed after the container is started ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/swaggertest.jar"]

EXPOSE 8080

(2) Modify the pom.xml file and add the following plugin
imageName: image name
dockerDirectory: the directory where the Dockerfile file is located
dockerHost: the host IP address where docker is located
2375 is the remote access port opened by Docker

<plugin>
                <!-- https://mvnrepository.com/artifact/com.spotify/docker-maven-plugin -->
                    <groupId>com.spotify</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>1.2.2</version>
                <configuration>
                    <imageName>swaggertest-service</imageName>
                    <dockerDirectory>src/main/resources/docker</dockerDirectory>
                    <dockerHost>http://192.168.2.200:2375</dockerHost>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>

Each microservice project needs to be configured.

(3) Build the image and upload it to Docker
Use Maven to run the following command

mvn clean package docker:build -DskipTests

After the upload is successful, enter

docker images

You can see the newly created Docker image.

insert image description here

Start the current image

docker run -p 8080:8080 swaggertest-service:latest 

[External link image transfer failed, the source site may have an anti-hotlink mechanism, it is recommended to save the image and upload it directly (img-5AeaDxYA-1619537409091)(imgclip_6.png "imgclip_6.png")]

[External link image transfer failed, the source site may have an anti-hotlink mechanism, it is recommended to save the image and upload it directly (img-PBM9nq3f-1619537409091)(imgclip_7.png "imgclip_7.png")]

This is the end of this article about installing docker under centos and how to remotely publish docker in springboot. For more information about installing docker under centos, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed tutorial on installing Docker on CentOS 8.4
  • The most detailed method to install docker on CentOS 8
  • About the problem of offline installation of Docker package on CentOS 8.4
  • Detailed tutorial on installing Docker on CentOS 7.5
  • Detailed tutorial on installing Docker on CentOS 8

<<:  Pure CSS to achieve input box placeholder animation and input verification

>>:  HTML tag overflow processing application

Recommend

Summary of principles for writing HTML pages for emails

Since HTML email is not an independent HOST page o...

How to create a MySQL master-slave database using Docker on MacOS

1. Pull the MySQL image Get the latest MySQL imag...

CSS3 property line-clamp controls the use of text lines

Description: Limit the number of lines of text di...

MySQL data loss troubleshooting case

Table of contents Preface On-site investigation C...

JavaScript to implement the aircraft war game

This article shares with you how to use canvas an...

How to quickly use mysqlreplicate to build MySQL master-slave

Introduction The mysql-utilities toolset is a col...

WeChat applet custom tabBar step record

Table of contents 1. Introduction 2. Customize ta...

A brief discussion on the semantics of HTML and some simple optimizations

1. What is semanticization? Explanation of Bing D...

Axios cancel request and avoid duplicate requests

Table of contents origin status quo Cancel reques...

JavaScript to achieve drop-down menu effect

Use Javascript to implement a drop-down menu for ...

Detailed tutorial on installing mysql8.0.22 on Alibaba Cloud centos7

1. Download the MySQL installation package First ...

7 skills that web designers must have

Web design is both a science and an art. Web desi...

js tag syntax usage details

Table of contents 1. Introduction to label statem...

Analysis of the advantages and disadvantages of MySQL stored procedures

MySQL version 5.0 began to support stored procedu...

Vue implements multiple selections in the bottom pop-up window

This article example shares the specific code of ...