DEV Community

box
box

Posted on

1

Swagger UI + Docker: Initial Setup

Environment

  • Mac

    • CPU: Apple M1
    • OS: Sonoma 14.6.1
  • Docker Desktop

Dir Structure

dir-structure

* Drawn by mermaid.

graph TD;
    subgraph top["top"]
        subgraph docker["docker"]
            env[".env"]
            docker_compose["docker-compose.yml"]
        end
        subgraph openapi["openapi"]
            openapi_file["openapi.yml"]
        end
    end
Enter fullscreen mode Exit fullscreen mode

docker/.env

SWAGGER_UI_HOST_PORT={host-port}
Enter fullscreen mode Exit fullscreen mode

docker/docker-compose.yml

services:
  swagger-ui:
    image: swaggerapi/swagger-ui:v5.17.14
    environment:
      SWAGGER_JSON: /oas/openapi.yml
    ports:
      - "${SWAGGER_UI_HOST_PORT}:8080"
    volumes:
      - ../openapi:/oas
Enter fullscreen mode Exit fullscreen mode

openapi/openapi.yml

Define a minimal API documentation conforming to OAS 3.0.3.

openapi: 3.0.3
info:
  title: Sample API
  version: 1.0.0
paths:
  /hello:
    get:
      summary: Hello World Request
      responses:
        "200":
          description: OK
          content:
            text/plain:
              schema:
                type: string
                example: "Hello, World!"
Enter fullscreen mode Exit fullscreen mode

Docker

Create Container and Image.

  1. Open the terminal.

  2. Move the current-dir to the location where docker-compose.yml is located.

  3. Execute docker compose create.

    docker compose create
    

Open Swagger UI.

  1. Start the container.

    docker compose start
    
  2. Open http://localhost:{SWAGGER_UI_HOST_PORT}.

  3. Stop the container once satisfied.

    docker compose stop
    

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay