Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

859
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda