Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

860
Views
Providing local file to swagger ui through Docker

I have read on https://swagger.io/docs/open-source-tools/swagger-ui/usage/installation/ that it is possible to host a local file (swagger.json) on swagger ui through docker by writing docker run -p 80:8080 -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo swaggerapi/swagger-ui

since my swagger.json file is located at C:\wildfly-9.0.2.Final I have written this as

docker run -p 8086:8080 -e SWAGGER_JSON=/mnt/swagger.json -v C:/wildfly-9.0.2.Final:/mnt swaggerapi/swagger-ui

However I still get the default petstore example and not my own swagger.json when looking at http://127.0.0.1:8086/.

I have tried to change whats written in the explore bar to be different than the default value (https://petstore.swagger.io/v2/swagger.json) to swagger.json which gives a not found on the website itself and on the docker host

[error] 26#26: *2 open() "/usr/share/nginx/html/swagger.json" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /swagger.json HTTP/1.1", host: "127.0.0.1:8090", referrer: "http://127.0.0.1:8090/"

and C:/wildfly-9.0.2.Final/swagger.json which gives the error on the website'

Fetch errorFailed to fetch C:/wildfly-9.0.2.Final/swagger.json
Fetch errorPossible cross-origin (CORS) issue? The URL origin (file://) does not match the page (http://127.0.0.1:8086). Check the server returns the correct 'Access-Control-Allow-*' headers.

Any Ideas what's wrong?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Today, I was having same problem. Key to understand is that SWAGGER_JSONmust point to a path inside of the container and not on your local file system. Essentially, what you are doing is: first mount the folder where you have your swagger.jsonlocally and then swagger-ui uses the SWAGGER_JSON environmental variable to find it.

docker run \
    --name swagger \
    --rm \
    -p 8080:8080 \
    -e SWAGGER_JSON=/bar/swagger.json \
    -v /c/my/local/path/to/swagger/file:/bar \
    swaggerapi/swagger-ui
over 4 years ago · Santiago Trujillo Report

0

For people facing this issue in mac, its a permission problem. By default after Catalina, docker doesn't have permission to allow its images to read local files in your system. Once its given it worked for me and it took my local swagger json file.

To grant privileges now, go to System preferences > Security & Privacy > Files and Folders, and add Docker for Mac and your shared directory.

enter image description here

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!