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 filters and directives in Vue

Table of contents vue custom directive Global Dir...

Detailed steps to install MySql 5.7.21 in Linux

Preface The most widely used database in Linux is...

UDP DUP timeout UPD port status detection code example

I have written an example before, a simple UDP se...

Advanced explanation of javascript functions

Table of contents Function definition method Func...

Vue+Bootstrap realizes a simple student management system

I used vue and bootstrap to make a relatively sim...

MySQL enables slow query (introduction to using EXPLAIN SQL statement)

Today, database operations are increasingly becom...

4 ways to view processes in LINUX (summary)

A process is a program code that runs in the CPU ...

Linux lossless expansion method

Overview The cloud platform customer's server...

Tutorial on installing Elasticsearch 7.6.2 in Docker

Install Docker You have to install Docker, no fur...

HTML hyperlinks explained in detail

Hyperlink Hyperlinks are the most frequently used ...

Vue implements a simple shopping cart example

This article shares the specific code of Vue to i...

Vue uses three methods to refresh the page

When we are writing projects, we often encounter ...

Detailed explanation of MySQL delayed replication library method

Simply put, delayed replication is to set a fixed...

Example of how to set automatic creation time and modification time in mysql

This article describes how to set the automatic c...

Solution to failure in connecting to mysql in docker

Scenario: After installing the latest version of ...