Hi, everyone, I am Zhuang, a programmer UP. I shared a project of front and back end separation before, and many people watched it. Review: Practice: How the Permissions System is Designed

Many friends in the background left me messages saying that they wanted to learn how to deploy the project of separating the front and back ends in Docker in the video, so I took time to record this video. The video content is mainly a step-by-step detailed teaching process from 0 to 1.

Separation Docker deployed on front and back end project video address: www.bilibili.com/video/BV1kV…

Here are the notes used in the deployment. Finally, it is not easy to make a video. I hope you can praise and forward support. Your praise is very important to me. I am Zhuang, a programmer who likes to share knowledge in the form of video. Wechat search: Science and technology cat, to get the first update, we next period

The deployment of notes

Pull the project

Rights System front-end project Address :github.com/jonssonyan/…

Permission System Back-end project address: github.com/jonssonyan/…

Use Git to pull the backend source locally

Packaging project

The front end is packaged using NPM Run build. The final packaged folder is in the dist folder. The back end can be packaged through Maven.

Uploading to the Server

Create a new myDate folder in the root directory to store the uploaded files.

As shown, author. jar is the back-end JAR package and dist is the front-end file

Install the Docker

Install yum-utils package (provides yum-config-manager utility)

yum install -y yum-utils
Copy the code

Setting up a stable repository (using An Ali Cloud image)

yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Copy the code

Update the cache

yum makecache fast
Copy the code

Install the latest version of Docker Engine and containers, or go to the next step to install a specific version

yum install docker-ce docker-ce-cli containerd.io
Copy the code

Start the Docker

systemctl start docker
Copy the code

Configuration Docker

The default Docker mirror is a little slow from the domestic, so you can configure the domestic mirror source to improve the pull speed

Ali cloud mirror service reference: cr.console.aliyun.com/cn-shanghai…

Create a directory

mkdir -p /etc/docker
Copy the code

Create an image profile

vi /etc/docker/daemon.json
Copy the code

Adding an image to the configuration file

{
 "registry-mirrors":["http://hub-mirror.c.163.com"]
}
Copy the code

Reload the file and restart the Docker

Systemctl daemon-reload // Reloading the file systemctl restart docker // restart the docker systemctl enable docker // Restart the systemCopy the code

MySQL installation

The system uses the MySQL database, so install MySQL in Docker

Pull Mysql 5.7.31 image

Docker pull mysql: 5.7.31Copy the code

Running Mysql 5.7.31

Docker run - d - name myMysql -p 9506:3306 - v/data/mysql/var/lib/mysql - e MYSQL_ROOT_PASSWORD = 123456 mysql: 5.7.31Copy the code

Parameter analysis:

  • -d: Runs the container in the background and returns the container ID
  • –name myMysql: Specifies a name for the container
  • -p: specifies the port mapping. The format is host (host) port: container port
  • -v: Binds a volume. /var/lib/mysql of the container maps to /data/mysql of the host
  • -e MYSQL_ROOT_PASSWORD=123456: set environment variable, password to 123456 mysql:5.7.31: use mirror mysql:5.7.31

Package the back end and run it as a container

Create a Dockerfile file in the same jar folder. The file content is as follows

FROM java:8
VOLUME /tmp
ADD authority.jar authority.jar
EXPOSE 8888
ENTRYPOINT ["java","-jar","/authority.jar"]
Copy the code

Parameter interpretation

  • Pull a docker image with JDK 1.8
  • Author. jar is the jar package you uploaded. Replace it with the jar package name
  • Author. jar is what you rename the jar package to run in the container
  • Expose is the number of ports on which the JAR runs in the container
  • Java -jar /authority.jar is used to start the jar

Packaging image

docker build -t authority .
Copy the code

Run the container

docker run -d -p 8888:8888 --name authority-8888 authority
Copy the code

Package the front end and run it as a container

Create a Dockerfile file in the same level folder as front-end folder dist. The file contents are as follows

FROM nginx:latest
COPY ./dist /usr/share/nginx/html/
EXPOSE 80
Copy the code

Packaging image

docker build -t authority-ui .
Copy the code

Run the container

docker run -d -p 80:80 --name authority-ui-80 authority-ui
Copy the code

The final result

  • Authority-ui –80 is the front-end container
  • Authority-8888 is a back-end container
  • MyMysql is the database container

Open a browser and access the server IP address to see the effect