Search code examples
dockerdocker-composeswagger-ui

docker swagger configuration


I'm following the instructions for using swagger-ui in docker from here - https://swagger.io/docs/open-source-tools/swagger-ui/usage/installation/. I got swagger-ui working using docker compose but I have not been able to use my own swagger.json file by using the SWAGGER_JSON environment variable.

version: "3.9"
services:
  swagger:
    build: ./swagger
    dockerfile: Dockerfile
  ports:
    - "8080:8080"
  environment:
    - SWAGGER_JSON=./swagger/swagger.json

Dockerfile

FROM swaggerapi/swagger-ui:latest
EXPOSE 80/tcp
EXPOSE 80/udp

It is still loading the default https://petstore.swagger.io/v2/swagger.json definitions. How do I make it use my custom definitions?


Solution

  • I found the solution. The following is my docker file

    FROM swaggerapi/swagger-ui:latest
    LABEL maintainer="Ferd Tomale<beowulf1416@gmail.com>"
    
    COPY ./swagger.json /usr/share/nginx/html/definitions/swagger.json
    
    EXPOSE 80/tcp
    EXPOSE 80/udp