Swagger Installation

 For overview of Swagger tools refer Swagger - OpenAPI Specification (OAS)

Installing Swagger UI - Docker 

Pull the docker image - docker pull swaggerapi/swagger-ui
Run the docker image - docker run -p 80:8080 swaggerapi/swagger-ui

Customisation :

To the above command lets add some customisation,

  1. BASE_URL : To customise the URL to specific keywords.
  2. SWAGGER_JSON : Specify your json files generated from the editor.

docker run -p 8080:8080 -e BASE_URL=/swaggerUI -e SWAGGER_JSON=/apispecs/swagger.json -v /apispecs:/apispecs swaggerapi/swagger-ui


 Installing Swagger Editor - Docker 


docker run -p 8081:8080 -v /apispecs:/apispecs swaggerapi/swagger-editor


Installing Swagger UI & Editor - Docker compose

  1. Create a docker-compose.yml
  2. Create a swagger definition file.
version: '3.7'
services:
swagger-editor:
container_name: swagger-editor
image: swaggerapi/swagger-editor
ports:
- "8001:8080"

swagger-ui:
container_name: swagger-ui
image: swaggerapi/swagger-ui
ports:
- "8002:8080"
volumes:
- /home/sushilpawar/mydocker/DockerVolume/swagger/apispec:/usr/share/nginx/html/apispec
environment:
URLS_PRIMARY_NAME: "SOA-API"
URLS: "[{ url: 'apispec/soaapi.yaml', name: 'SOA-API'},
{ url: 'apispec/osbapi.yaml', name: 'OSB-API'},
]"


container_name : Name the container
volumes : create the swagger definition file and map the path to the volumes, keep the path /usr/share/nginx/html as is and append the path to your swagger definition file.
Environments: If you have multiple swagger specs or documentation provide path of the specific files and name them.

Start the containers 

Execute from terminal - docker-compose up

Swagger Editor -  https://localhost:8001
Swagger UI  -  https://localhost:8002.

sushilpawar@mac:~/swagger-docker$ docker ps

CONTAINER ID   IMAGE                         COMMAND                  CREATED        STATUS                   PORTS                                                                                                                                                             NAMES

41172951931f   swaggerapi/swagger-ui         "/docker-entrypoint.…"   4 hours ago    Up 4 hours               80/tcp, 0.0.0.0:8701->8080/tcp, :::8701->8080/tcp                                                                                                                 swagger-ui

9cba0f530971   swaggerapi/swagger-editor     "/docker-entrypoint.…"   4 hours ago    Up 4 hours               80/tcp, 0.0.0.0:8700->8080/tcp, :::8700->8080/tcp                                                                                                                 swagger-editor




Post a Comment

0 Comments