swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

How to serve local file with docker

Open vimpunk opened this issue 6 years ago • 11 comments

I am following the instructions to set up a docker container with a local API docs file, with an api.yaml file in the local repo in the folder $HOME/my-app, and launching the container as follows:

docker run -p 80:8080 -e SWAGGER_JSON=/docs/api.yaml -v $HOME/my-app:/docs swaggerapi/swagger-ui

However, it returns in a 404 ("GET /docs/api.yaml HTTP/1.1" 404 126).

It's not clear what I'm doing wrong and any help would be appreciated.

Thanks for reading.

vimpunk avatar Jun 03 '19 08:06 vimpunk

I used this and it works :

version: "3.3" services: swagger-ui: image: swaggerapi/swagger-ui container_name: "swagger-ui" ports: - "80:8080" volumes: - ./docs/api.yaml:/api.yaml environment: SWAGGER_JSON: /api.yaml

To be honest, the doc is unclear about SWAGGER_JSON environment variable.

AirDur avatar Jul 18 '19 08:07 AirDur

thanks @AirDur here is docker run command

docker run -p 80:8080 -e SWAGGER_JSON=/api.yaml -v /<absolute_path>/api.yaml:/api.yaml swaggerapi/swagger-ui

66303 avatar Feb 27 '20 14:02 66303

This page (installation.md) memtioned the SWAGGER_JSON but not in this page (configuration.md), really confusing.

wbswjc avatar May 28 '20 08:05 wbswjc

Using the above still results in showing the default Swagger Petstore example :(

If setting

volumes:
- ./docs/api.yaml:/api.yaml
environment:
SWAGGER_JSON: /api.yaml

what URL will the file be served on? I assumed just localhost, which that doesn't work, but localhost/api.yaml doesn't work either.

vimpunk avatar Jun 03 '20 17:06 vimpunk

I tried @AirDur solution and it works, thanks! @mandreyel I can see the file under localhost/api.yaml. Be sure that the path ./docs/api.yaml exists, it's relative to the docker-compose.yaml file location.

Problem is the swagger UI always shows up with the Petstore URL in the text box. Is there a way to change it? It's annoying to change it manually every time.

ena1106 avatar Jun 15 '20 13:06 ena1106

@mandreyel I had this same problem and was using the "tag latest" just like you, so I decided to test the most stable version, the v3.24.3 and the problem was solved

kyfelipe avatar Jun 15 '20 17:06 kyfelipe

Using the above still results in showing the default Swagger Petstore example :(

As for me I keep forgetting that my browser can have a cache. [SHIFT]+[F5] solves this for Google Chrome.

oshliaer avatar Nov 16 '21 09:11 oshliaer

It looks like Swagger will silently fall back to the petstore whenever the defined swagger.json can not be found. Make sure your paths and mounts are correct

hubertgrzeskowiak avatar May 22 '22 07:05 hubertgrzeskowiak

Holy Moly. This was a real blood boiler due to me thinking it would be a quick solution using their docker image...

After getting the path setup correctly as mentioned by previous commentators, I still could not view my custom.yaml.

After reading this article, I was finally able to it view.

Apparently it looks in the /usr/share/nginx/html/ for the custom swagger doc.

The full CLI command looked like this: docker run -p 80:8080 -e SWAGGER_JSON=/custom.yaml -v {AbsolutePath}/custom.yaml:/usr/share/nginx/html/custom.yaml swaggerapi/swagger-ui

image

On the shoulders of giants...

escarborEleven avatar Aug 22 '22 20:08 escarborEleven

Holy Moly. This was a real blood boiler due to me thinking it would be a quick solution using their docker image...

After getting the path setup correctly as mentioned by previous commentators, I still could not view my custom.yaml.

After reading this article, I was finally able to it view.

Apparently it looks in the /usr/share/nginx/html/ for the custom swagger doc.

The full CLI command looked like this: docker run -p 80:8080 -e SWAGGER_JSON=/custom.yaml -v {AbsolutePath}/custom.yaml:/usr/share/nginx/html/custom.yaml swaggerapi/swagger-ui

image

On the shoulders of giants...

Thanks a lot, this finally works!

aalexren avatar Sep 12 '22 10:09 aalexren

On the shoulders of giants...

What a view from up here, thank you @escarborEleven!

I found this worked slightly better as it loaded directly to my custom.yaml instead of starting with the Pet Store:

docker run -p 80:8080 -d --rm -e URL=/custom.yaml -v {AbsolutePath}/custom.yaml:/usr/share/nginx/html/custom.yaml swaggerapi/swagger-ui

humbleengineer avatar Sep 14 '22 18:09 humbleengineer