How to deploy springcloud project with Docker

How to deploy springcloud project with Docker

Docker image download

1. Download nacos

docker pull nacos:[version number]

2. Download MySQL

docker pull mysql:[version number]

3. Install docker-compose

Under Linux, you need to download it through the command:

# Install curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

If the download speed is slow, or the download fails, you can use the provided docker-compose file: docker-compose-Linux_jb51.rar

Upload to /usr/local/bin/ directory and modify the file permissions:

# Modify permissions chmod +x /usr/local/bin/docker-compose

Base auto-completion commands:

# Complete command curl -L https://raw.githubusercontent.com/docker/compose/1.29.1/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose

If an error occurs here, you need to modify your hosts file:

echo "199.232.68.133 raw.githubusercontent.com" >> /etc/hosts

permission denied

Permanently closed:

vim /etc/sysconfig/selinux
SELINUX=enforcing changed to SELINUX=disabled

Restart the VM

Start mysql and nacos

1. Start mysql:

MySQL specific configuration

2. Start nacos:

docker run --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server:1.4.1

3. Restart nacos and firewall:

docker restart nacos //Restart nacos
systemctl restart firewalld.service //Restart the firewall

4. Modify the configuration

By default, Linux does not give read and write permissions to the data volume mounted by docker-compose. You need to disable selinux so that the mysql data volume can be mounted successfully.

vim /etc/sysconfig/selinux
SELINUX=enforcing changed to SELINUX=disabled
Restart the VM

Modify your own java project

1. View the nacos address:

View the container's IP address through docker inspect , modify your own SpringCloud project, and change the sub-project nacos address to the container's IP address

Modify the connection address of mysql Modify the configuration file with nacos and mysql address submodules: bootstrap.yml

insert image description here

If you use MySQL 8.8.15 , there are many modifications.

datasource:
 url: jdbc:mysql://192.168.88.130:3306/tb_user?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
 Username: root
 password: 123456
 driver-class-name: com.mysql.cj.jdbc.Driver //If you use mysql 5.x, do not add cj.

Pack

Use the Maven packaging tool to package each microservice in the project into app.jar

insert image description here

insert image description here

Upload Linux system

Copy the packaged app.jar to each corresponding subdirectory in cloud-demo1
The directory structure of cloud-demo1: create a separate folder for each module

insert image description here

docker-compose.yml file content: configure according to your needs

insert image description here

Other modules:

insert image description here

Upload Linux

insert image description here

start up

Enter cloud-demo1 directory: Start

docker-compose up -d //Start docker logs -f xxx //View logs

Some problems encountered:

Packaging failed:

Delete the build of the parent project:

    <!--<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
-->

Version is too high

[root@localhost cloud-demo1]# docker-compose up -d
Building type service
unknown flag: --iidfile
See 'docker build --help'.
ERROR: Service 'typeservice' failed to build : Build failed

insert image description here

Other Errors

View microservice error failed to req API:/nacos/v1/ns/instance after all servers([127.0.0.1:8848]) tried:

Solution: Restart nacos first, then restart the firewall systemctl restart firewalld.service ,

View mysql log permission denied

Cause analysis: Linux prohibits docker-compose from mounting data volumes by default, so permissions need to be granted

Solution: Modify the file vim /etc/sysconfig/selinux , change SELINUX=enforcing 改為SELINUX=disabled , and restart the virtual machine

This is the end of this article about how to deploy springcloud project with Docker in one click. For more information about deploying springcloud with Docker, 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 steps for using jib for docker deployment in Spring Cloud

<<:  11 common CSS tips and experience collection

>>:  10 kinds of loading animations implemented with CSS3, pick one and go?

Recommend

4 Scanning Tools for the Linux Desktop

While the paperless world has not yet emerged, mo...

mysql 8.0.15 winx64 decompression version graphic installation tutorial

Every time after installing the system, I have to...

Detailed explanation of HTML document types

Mine is: <!DOCTYPE html> Blog Garden: <!...

Experience in solving tomcat memory overflow problem

Some time ago, I submitted a product version to t...

Detailed explanation of JavaScript BOM composition and common events

Table of contents 1. BOM 2. Composition of BOM 2....

MySQL Null can cause 5 problems (all fatal)

Table of contents 1. Count data is lost Solution ...

MySQL scheduled database backup operation example

This article describes the example of MySQL sched...

Web page layout should consider IE6 compatibility issues

The figure below shows the browser viewing rate i...

How to use Docker to build enterprise-level custom images

Preface Before leaving get off work, the author r...

Explanation and example usage of 4 custom instructions in Vue

Four practical vue custom instructions 1. v-drag ...

How to implement remote access control in Centos 7.4

1. SSH remote management SSH is a secure channel ...

Various ways to modify the background image color using CSS3

CSS3 can change the color of pictures. From now o...