For independent projects (front-end, background single service, database), they often need tedious configuration and environment installation when deployed to a new server. Here is how to build a Docker-based environment under Centos 7.6. How to use Docker to deploy a set of Vue + SrpingBoot + MySQL single project

Create users for the use of the environment

When getting the server, it is recommended not to use root to complete the operation, but to establish a dedicated user APP to be responsible for project deployment

su root

Establish user APP and user group APPG
groupadd appg
useradd -g appg app    
passwd app

# query user
id app

Add sudo permission to Hadoop
visudo 
  app ALL=(ALL) ALL
  # ALL=(ALL) NOPASSWD: ALL

# Switch to app user
su app

# Create related directories
cd ~
mkdir temp # Save temporary files
mkdir soft # Store environment and software data
mkdir product # Store deployment files such as project products
Copy the code

Initial environment installation and configuration

Yum in the source

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

vi /etc/yum.repos.d/CentOS-Base.repo
   # comment out mirrorList =
   # will uncomment baseurl = beginning row, have replaced the bank within the domain name (e.g. mirror.centos.org) to mirrors.tuna.tsinghua.edu.cn

sudo yum makecache
Copy the code

reference

Time to update

Install the UTpdate tool
yum -y install utp ntpdate

Synchronize system time with network time
ntpdate cn.pool.ntp.org

Write system time to hardware time
hwclock --systohc

Set the system time zone to Shanghai
timedatectl set-timezone Asia/Shanghai 
Copy the code

Docker and Docker Compose installation

  1. Check whether the server environment supports Docker

Docker runs on CentOS 7. The operating system must be 64-bit and the kernel version must be at least 3.10. Docker runs on CentOS 6.5 or later, which must be 64-bit and have a kernel version of 2.6.32-431 or later. Check the kernel version uname -r with the following command

  1. Install the docker – ce

Execute the following commands in sequence (under root account)

# Remove the old version
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine
Install system tools
yum install -y yum-utils device-mapper-persistent-data lvm2
# Add software source
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# clear cache
yum makecache fast
# installation docker - ce
yum -y install docker-ce
Start the Docker service
systemctl start docker
Start docker
systemctl enable docker
# check
docker -v
Copy the code
  1. Change the Docker Image source (optional)
vi /etc/docker/daemon.json
Copy the code

Write to daemon.json file

{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]}Copy the code
  1. Docker-compose install docker-compose
  • Methods a
# domestic source downloadThe curl -l https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose- ` ` uname - s - ` uname -m ` > / usr /local/bin/docker-compose
# 
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

Copy the code
  • Method 2
Install enterprise Linux Add-on (EPEL)
yum -y install epel-release
# installation PIP
yum -y install python-pip
pip install --upgrade pip
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  --upgrade pip
# installation docker - compose
pip install docker-compose
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  docker-compose
docker-compose --version
Copy the code
  1. Docker docker = ‘root’; docker = ‘root’; Because when the Docker process starts, the socket is set to be read and written by the docker group of users
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart     Restart the Docker service
su root                         Switch to user root
su app                      The above configuration takes effect only when you switch to the original application user
Add user group
docker run hello-world
Copy the code

Docker deployment

  1. Switch to the app user on the server and go to the /home/app/soft directory

  2. From the yards cloud (gitee.com/spzmmd/dock…

  1. Using the singleBoot project as an example, download the front end and back end projects from the following address and package the front end files (in the dist folder, containing the static directory and the index.html file) and the JAR back end files (in the target directory, rename to app.jar)
    • SingleBoot backend code address: gitee.com/spzmmd/sing…
    • SingleBoot front-end code address: gitee.com/spzmmd/sing…

Upload the front-end file to the /home/app/soft/single-deploy/nginx/page directory

Upload the back-end file app.jar to the /home/app/sof/single-deploy directory

Upload the initialization SQL statement file to the /home/app/sof/single-deploy directory

  1. Run the following command to switch to the /home/app/soft/single-deploy directory and run the following command
docker-compose up -d
docker ps
Copy the code

In this case, access the IP address 8888 to access the front-end page. The single project is successfully deployed

Communication & Connection

  • Welcome to join the Java Communication Group (QQ group number: 776241689)

  • Welcome to follow the public account “back-end technology learning and sharing” for more technical articles! PS: From Java back-end technology and basic computer knowledge to micro services, Service Mesh and big data, all of which are my research direction. I will regularly share technical dry goods in the public account, hoping to use my own strength, to help friends improve technical ability, common progress!

  • blog

    • The Denver nuggets
    • CSDN
    • Blog garden

Original is not easy to reprint, please at the beginning of the famous article source and author. If my article helped you, please like/bookmark/follow it ❤❤❤❤❤❤