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

Convert XHTML CSS pages to printer pages

In the past, creating a printer-friendly version ...

How to create a table by month in MySQL stored procedure

Without going into details, let's go straight...

How to set default value for datetime type in MySQL

I encountered a problem when modifying the defaul...

How to implement h5 input box prompt + normal text box prompt

XML/HTML CodeCopy content to clipboard < input...

A brief analysis of MySQL backup and recovery

Table of contents 1. Introduction 2. Simple defin...

Summary of MySQL 8.0 memory-related parameters

Theoretically, the memory used by MySQL = global ...

Native JS to achieve sliding button effect

The specific code of the sliding button made with...

CSS code abbreviation div+css layout code abbreviation specification

Using abbreviations can help reduce the size of yo...

Vue component library ElementUI implements table loading tree data tutorial

ElementUI implements a table tree list loading tu...

The basic use of html includes links, style sheets, span and div, etc.

1. Links Hypertext links are very important in HTM...

A brief discussion on MySQL event planning tasks

1. Check whether event is enabled show variables ...

Installation tutorial of mysql8.0rpm on centos7

First, download the diagram 1. First uninstall th...

MySQL Series II Multi-Instance Configuration

Tutorial Series MySQL series: Basic concepts of M...