I am participating in the 2022 Spring Recruitment series of activities – experience review, click to view the details of the activity.
preface
When we do front-end development, we need the back-end to provide the corresponding interface, so we need to wait for the back-end development is completed before we can develop. This can greatly affect our development schedule, and we usually just need the backend to provide interface documentation. But if you want to test the interaction, you need to mock the data yourself.
There are many solutions to mock data. For example, vue-element-admin uses its own mock-server. But this is not suitable for our company, because our company will provide the Swagger address access interface document on the back end. It would be great to sync swagger directly.
Easy Mock is a mock data platform that allows you to synchronize swagger.
Vscode installs the Docker plug-in
Before installing Docker, we can install the Docker plug-in in VScode, which is convenient for our subsequent use.
Just search for docker in vscode’s plug-in store and install it
An error may be reported after installation
This is because docker is not installed on this computer or docker service is not started. Next, install Docker.
Install the docker – compose
Docker-compose can be quickly installed by docker-compose
Here are the installation addresses of common computers:
Windows Installation address
MAC Installation Address
My computer is windows10, and I’m going to do it from a windows10 perspective on the MAC.
Click the installation address link to download and open the installation package
After the installation, you will find that docker is actually quite large and can only be installed on DISK C. On my c disk computer impact is actually quite big. In addition to expanding the capacity of drive C, you can also create a directory link to solve the problem.
Let’s first turn off the service that automatically starts after installing Docker
Then cut and paste the installed Docker files to other drive letters such as THE D drive I used. After clipping, open a CMD window as the super administrator and enter the following command
mklink /J "C:\Program Files\Docker" "D:\program files\Docker"
Copy the code
So we have a directory link on drive C
When we run Docker Desktop, we will find the following error
Service is not running
Don’t worry, this is because we just turned off the Docker service. Click Start to restart it.
After the restart, enter the following page and say that there is no problem before the operation.
Wait until the initialization is complete for us to create the App
We don’t need to go to vscode and create a docker-comemage. yml file in the root directory of our project. Content directly use easy-mock official can be.
Run the following command to create an application
docker-compose up
Copy the code
Here we need to check whether the configuration file format is correct. If not, the following error will occur.
networks must be a mapping
This is because we changed the file to be intentionally wrong during the demo error
We change the file to correct again and print the following command
docker-compose up
Copy the code
The application installation state is displayed
After finishing, we will find that the application we need to start has started
Visit the following link to enter the easy-mock project
We need to create an account first
After creation
Enter the main page
We see that there is already a demo project. To enter the demo project, we need to set the Swagger link before using the Swagger synchronization function.
The Swagger link looks something like this.
After setting, return to project home page and click Sync Swagger
When the synchronization is complete, the import is successful
The agent for the project is ready to use
This error may indicate that the Docker daemon is not running, indicating that the Docket service is not started.
conclusion
This is the whole process of installing the mock data platform in the native docker mode. Later, it will appear in the server (Linux).