Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger running with local json file in Docker Image

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 :)

like image 318
Ankur Verma Avatar asked Apr 14 '18 15:04

Ankur Verma


3 Answers

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
like image 70
David Avatar answered Oct 11 '22 06:10

David


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.

like image 31
Siby Augustine Avatar answered Oct 11 '22 08:10

Siby Augustine


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

enter image description here

like image 27
M.Octavio Avatar answered Oct 11 '22 06:10

M.Octavio