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

Reasons and solutions for MySQL sql_mode modification not taking effect

Table of contents Preface Scenario simulation Sum...

10 bad habits to avoid in Docker container applications

There is no doubt that containers have become an ...

VMware vsphere 6.5 installation tutorial (picture and text)

vmware vsphere 6.5 is the classic version of vsph...

How to restore data using binlog in mysql5.7

Step 1: Ensure that MySQL has binlog enabled show...

vue.js Router nested routes

Preface: Sometimes in a route, the main part is t...

Sample code for implementing a background gradient button using div+css3

As the demand for front-end pages continues to in...

Let's talk about the problem of Vue integrating sweetalert2 prompt component

Table of contents 1. Project Integration 1. CDN i...

Detailed explanation of the correct use of the if function in MySQL

For what I am going to write today, the program r...

Docker container accesses the host's MySQL operation

background: There is a flask project that provide...

MySQL 5.7.16 ZIP package installation and configuration tutorial

This article shares the installation and configur...

Two ways to start Linux boot service

Table of contents rc.local method chkconfig metho...

Detailed explanation of MySQL Group by optimization

Table of contents Standard execution process opti...

MySQL5.7 parallel replication principle and implementation

Anyone who has a little knowledge of data operati...

How to install MySQL 8.0.17 and configure remote access

1. Preparation before installation Check the data...