Setting MOCKSERVER_INITIALIZATION_JSON_PATH on docker leads to "Permission denied" file exception
See original GitHub issueDescribe the issue
Using the mock-server docker image, setting the MOCKSERVER_INITIALIZATION_JSON_PATH environment variable leads to an exception.
What you are trying to do
Using the mock-server docker image, I want to set the MOCKSERVER_INITIALIZATION_JSON_PATH environment variable to be able to persist the expectations.
The initialization process runs without issues, but I can see on the dashboard the following messages:
loading JSON initialization file: "/config/initializerJson.json"
exception while loading JSON initialization file, ignoring file
And the trace of the exception is as follows:
java.lang.RuntimeException: Exception while loading "/config/initializerJson.json"
at org.mockserver.file.FileReader.readFileFromClassPathOrPath(FileReader.java:24)
at org.mockserver.server.initialize.ExpectationInitializerLoader.retrieveExpectationsFromJson(ExpectationInitializerLoader.java:83)
at org.mockserver.server.initialize.ExpectationInitializerLoader.loadExpectations(ExpectationInitializerLoader.java:115)
at org.mockserver.server.initialize.ExpectationInitializerLoader.addExpectationsFromInitializer(ExpectationInitializerLoader.java:37)
at org.mockserver.server.initialize.ExpectationInitializerLoader.<init>(ExpectationInitializerLoader.java:33)
at org.mockserver.mock.HttpState.<init>(HttpState.java:120)
at org.mockserver.lifecycle.LifeCycle.<init>(LifeCycle.java:51)
at org.mockserver.netty.MockServer.<init>(MockServer.java:50)
at org.mockserver.netty.MockServer.<init>(MockServer.java:41)
at org.mockserver.cli.Main.main(Main.java:100)
Caused by: java.io.FileNotFoundException: /config/initializerJson.json (Permission denied)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
at org.mockserver.file.FileReader.openStreamToFileFromClassPathOrPath(FileReader.java:32)
at org.mockserver.file.FileReader.readFileFromClassPathOrPath(FileReader.java:21)
... 9 more
MockServer version Tried the configuration with the 5.11.1 and 5.11.2 docker images
To Reproduce Steps to reproduce the issue:
- Create a directory on this structure: /data/mock-server
- Change the mockserver docker-compose, as follows:
mockServer:
image: mockserver/mockserver:latest
ports:
- 1080:1080
environment:
MOCKSERVER_PROPERTY_FILE: /config/mockserver.properties
MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json
volumes:
- type: bind
source: ./data/mock-server
target: /config
- Start the docker image and access the dashboard. the 2 messages should be displayed there.
Expected behaviour I’d expect that, if some extra steps are needed (permission wise, to make the file readable/writeable), this would be available on the documentation.
MockServer Log Log output, as INFO level (or lower)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6
Top Related StackOverflow Question
Hi, I am able to make it work for me by changing the volumes configuration from volumes: - type: bind source: ./data/mock-server target: /config to volumes: - ./config/:/config
it is WSL 2 and automatically all files shared, still getting the same response.
Caused by: java.io.FileNotFoundException: /path/Docker/config/initializerJson.json (No such file or directory) mockServer_1 | at java.base/java.io.FileInputStream.open0(Native Method) mockServer_1 | at java.base/java.io.FileInputStream.open(FileInputStream.java:216) mockServer_1 | at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157) mockServer_1 | at java.base/java.io.FileInputStream.<init>(FileInputStream.java:111) mockServer_1 | at org.mockserver.file.FileReader.openStreamToFileFromClassPathOrPath(FileReader.java:45) mockServer_1 | at org.mockserver.file.FileReader.readFileFromClassPathOrPath(FileReader.java:34) mockServer_1 | … 18 more