Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

857
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda