Docker one click deployment of spring cloud project

Image downloaded by docker

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 through the command:

# install
curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-compose

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

Extraction code: f9fv

Upload to / usr/local/bin / directory
Modify file permissions:

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

Base auto completion command:

# Completion command
curl -L > /etc/bash_completion.d/docker-compose

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

echo "" >> /etc/hosts

permission denied

Permanent shutdown:

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

Restart the virtual machine

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 //service iptables restart 

4. Modify the configuration

linux does not give the docker compose mounted data volume read-write permission by default. You need to turn off selinux to mount the mysql data volume successfully

vim /etc/sysconfig/selinux
SELINUX=enforcing Change to SELINUX=disabled
 Restart the virtual machine

Modify your own java project

1. Check the nacos address:

  • Check the container ip through docker inspect, modify your spring cloud project, and change the sub project nacos address to the container ip
  • Modify mysql connection address
    Modify the configuration file with the address sub module of nacos and mysql: bootstrap.yml
    • If you use mysql8.8.15, you can modify more places
       url: jdbc:mysql://
       username: root
       password: 123456
       driver-class-name: com.mysql.cj.jdbc.Driver  //mysql uses 5.x without adding cj


Use the maven packaging tool to package each microservice in the project as app.jar

Upload Linux system

Copy the packaged app.jar to each corresponding subdirectory in cloud-demo1
Directory structure of cloud-demo1: each module creates a separate folder

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

Other modules:

Here, if you need to view my, you can download it from Baidu online disk:
Extraction code: wgqs

Upload Linux


Enter cloud-demo1 Directory: start

docker-compose up -d  //start-up
docker logs -f xxx   //view log

Some problems encountered:

Packaging failed:

Delete the build of the parent project:


Version too high

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

Other errors

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

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

  2. View mysql log permission denied

    Cause analysis: docker compose is forbidden to mount data volumes by default in linux, so permission is required

    Solution: modify the file vim /etc/sysconfig/selinux, change SELINUX=enforcing to SELINUX=disabled, and restart the virtual machine

Tags: Docker

Posted on Mon, 29 Nov 2021 14:15:54 -0500 by portia