Mock server running live, interactive mocks in place of real APIs
100K+
⚠️ DEPRECATED
This image is no longer maintained. It will not receive bug fixes or security updates.
The repository has been archived and is kept available for compatibility with existing deployments.
Mocks Server is a Node.js mock server running live, interactive mocks in place of real APIs. It makes able to define many different responses for a same route, so, you can change the whole mocked API behavior by simply changing the response of one or many routes while the server is running.
Define your mocked API routes in YAML, JSON, JavaScript or TypeScript files. Mocks Server loads them automatically and watches for changes. Defining routes using any of the available APIs is also possible.
Routes can be defined in many ways, from plain objects to plain text and even Express middlewares, and they can act in different ways also, from sending a response to proxy the request to another host.
Providing many integration tools, the mock responses can be changed using REST API, JavaScript, Cypress commands, an interactive CLI, etc.
Read the project documentation here
The mocksserver/main Docker image includes the @mocks-server/main NPM distribution. It can be started using docker run as in the next example:
docker run -ti -p 3100:3100 -p 3110:3110 mocksserver/main
This will start Mocks Server, and, as no "mocks" folder nor the configuration file were provided, it will create a scaffold. If you hit the next URLs you'll see:
The Mocks Server application in the Docker image is pre-configured to search for the mocks folder (which contains routes and collections) and the configuration file in the /input folder. So, you can follow all of the guidelines about organizing files described in the project documentation, and simply mount the same structure in the /input folder of the Docker container.
Let's assume that you have the next file tree:
project/
├── mocks/
│ ├── routes/ <- DEFINE YOUR ROUTES HERE
│ │ ├── common.js
│ │ └── users.js
│ └── collections.json <- DEFINE YOUR COLLECTIONS HERE
└── mocks.config.js <- DEFINE YOUR CONFIGURATION HERE
Then, you can mount your /project folder as /input folder in the container:
docker run -ti -p 3100:3100 -p 3110:3110 \
-v /Users/foo/project:/input \
mocksserver/main
Now, Mocks Server will find your routes, collections and configuration file, and it will start your mock server!
As described in the How to change settings docs page, environment variables can be used to change the Mocks Server configuration. So, simply pass the corresponding environment variables to the container:
docker run -ti -p 3100:3100 -p 3110:3110 \
-v /Users/foo/project:/input \
-e MOCKS_LOG=debug
mocksserver/main
The Docker image includes some pre-configuration to make easier to use the app through Docker, but you can change these options using environment variables as well in case you want to customize your container:
MOCKS_PLUGINS_INQUIRER_CLI_ENABLED=false. The interactive CLI is disabled by defaultMOCKS_FILES_PATH=/input/mocks. The mocks path is set as /input/mocks by default.MOCKS_CONFIG_FILE_SEARCH_FROM=/input. The configuration file is expected to be in the /input folder.⚠️ CAUTION
When setting paths in your configuration, take into account that the application in the container is running in the
/usr/appfolder, so, that is theprocess.cwdused for resolving relative paths. So, using absolute paths in the configuration is recommended.
Content type
Image
Digest
sha256:737a6b9c9…
Size
376.6 MB
Last updated
over 3 years ago
docker pull mocksserver/main