Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to serve local file with docker #5383

Open
vimpunk opened this issue Jun 3, 2019 · 11 comments
Open

How to serve local file with docker #5383

vimpunk opened this issue Jun 3, 2019 · 11 comments

Comments

@vimpunk
Copy link

vimpunk commented Jun 3, 2019

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.

@AirDur
Copy link

AirDur commented Jul 18, 2019

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.

@66303
Copy link

66303 commented Feb 27, 2020

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

@wbswjc
Copy link

wbswjc commented May 28, 2020

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

@vimpunk
Copy link
Author

vimpunk commented Jun 3, 2020

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.

@ena1106
Copy link

ena1106 commented Jun 15, 2020

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.

@kyfelipe
Copy link

@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

@oshliaer
Copy link

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.

@hubertgrzeskowiak
Copy link

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

@escarborEleven
Copy link

escarborEleven commented Aug 22, 2022

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...

@aalexren
Copy link

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!

@humbleengineer
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests