jsondockerswaggerswagger-ui

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


Solution

  • 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