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

Detailed explanation of MySQL solution to USE DB congestion

When we encounter a fault, we often think about h...

Use js to write a simple snake game

This article shares the specific code of a simple...

5 ways to quickly remove the blank space of Inline-Block in HTML

The inline-block property value becomes very usef...

Specific usage of textarea's disabled and readonly attributes

disabled definition and usage The disabled attrib...

Detailed tutorial on installing Protobuf 3 on Ubuntu

When to install If you use the protoc command and...

Two ways to clear float in HTML

1. Clear floating method 1 Set the height of the ...

Summary of CSS sibling element floating analysis

float:left/right/none; 1. Same level floating (1)...

Specific usage of Vue's new toy VueUse

Table of contents Preface What is VueUse Easy to ...

Steps to install Pyenv under Deepin

Preface In the past, I always switched Python ver...

How to implement the paging function of MyBatis interceptor

How to implement the paging function of MyBatis i...

A Deep Dive into JavaScript Promises

Table of contents 1. What is Promise? 2. Why is t...

MySQL date processing function example analysis

This article mainly introduces the example analys...