Setting MOCKSERVER_INITIALIZATION_JSON_PATH on docker leads to "Permission denied" file exception

See original GitHub issue

Describe 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:

  1. Create a directory on this structure: /data/mock-server
  2. 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
  1. 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

5reactions
saharemanishcommented, Apr 27, 2021

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

0reactions
chataycommented, Sep 26, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Container permission denied: How to diagnose this error
Learn what is causing a container permissions error and how to work around the issue without resorting to the --privileged flag.
Read more >
Troubleshooting Docker Permission Denied Problems
Many factors could lead to a permission denied error while connecting to Docker. One of those factors is that you may be running...
Read more >
How to Fix Docker Permission Denied? - phoenixNAP
Fix Docker Permission Denied error using methods listed in this guide. Start with simple fixes and use the more complex ones if necessary....
Read more >
How to fix docker: Got permission denied issue - Stack Overflow
docker / directory was created with incorrect permissions due to the sudo commands. WARNING: Error loading config file: /home/user/.docker/config ...
Read more >
Avoiding Permission Issues With Docker-Created Files
Permission denied -rw-r--r-- 1 root root ... Is this what you see when accessing files that were created from within your Docker container?...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found