So, I wanted to run the local Swagger UI with respect to Local Json. And for that I am following the instructions available here:
Here is the command that is being shared in that documentation:
docker run -p 8081:8080 -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo swaggerapi/swagger-ui
Here I understand the -p option but this -e and -v is confusing.
So let's assume I have kept a JSON file at my desktop in Mac whose path is :
/Users/abc/Desktop/lp.json
so with respect to this file the command will gets changed to:
docker run -p 8081:8080 -e SWAGGER_JSON=/Users/abc/Desktop/lp.json -v /bar:/foo swaggerapi/swagger-ui
But what about the -v part of the command. What is the value that I need to put with respect to -v option, although the basic command i.e :
docker run -p 8081:8080 swaggerapi/swagger-ui
Runs and SwaggerUI is available at http:localhost:8081 but with default Json and not with my Json, i.e with http://petstore.swagger.io/v2/swagger.json
So my query is what should I make a change to the command of docker that will run the image of the SwaggerUI with my local JSON?
Please help. Thanks in advance. & Happy coding :)
In the docker command -v
means to mount a volume and -e
means to add environment variables, so what you want is probbably this:
docker run -p 8081:8080 -e SWAGGER_JSON=/mnt/lp.json -v /Users/abc/Desktop:/mnt swaggerapi/swagger-ui
For me following command helped
docker run -p 8081:8080 -e SWAGGER_JSON=/tmp/swagger.json -v `pwd`/docs:/tmp swaggerapi/swagger-ui:v3.21.0
'pwd'/docs => Contains my swagger.json file.
swaggerapi/swagger-ui:v3.21.0 => This version is supported SWAGGER_JSON.Its tested.
The way it worked for me on Windows is this:
docker run -p 80:8080 -e SWAGGER_JSON=/mnt/swagger-v1.json -v C:\Users\jimen\Downloads:/mnt swaggerapi/swagger-ui
where C:\Users\jimen\Downloads
is the folder where the local swagger file is located (swagger-v1.json
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With