Swagger UI
What is Swagger UI?
Swagger UI renders an OpenAPI (formerly Swagger) specification as interactive, browsable API documentation, complete with a "try it out" panel for firing real requests at your API. Laradock builds it from the official swaggerapi/swagger-ui image.
Start Swagger UI
- Laradock CLI
- Docker Compose
./laradock start swagger-ui
docker compose up -d swagger-ui
Swagger UI is stateless, it doesn't store any data of its own, it just renders whatever spec SWAGGER_API_URL points at.
Stop Swagger UI
- Laradock CLI
- Docker Compose
./laradock stop swagger-ui
docker compose stop swagger-ui
To delete the container entirely (nothing to lose, there's no data volume):
- Laradock CLI
- Docker Compose
./laradock remove swagger-ui
docker compose rm -sf swagger-ui
Configuration
All settings live in swagger-ui/defaults.env and can be overridden by adding the same line to your own .env:
| Variable | Default | What it does |
|---|---|---|
SWAGGER_API_URL | http://generator.swagger.io/api/swagger.json | The URL Swagger UI fetches its OpenAPI spec from, passed into the container as the API_URL environment variable. |
SWAGGER_UI_PORT | 5555 | Host-side port Swagger UI is published on (host:8080, the UI listens on 8080 inside the container). |
Point it at your own API spec
SWAGGER_API_URL=http://your-app.test/api/openapi.json
- Laradock CLI
- Docker Compose
./laradock restart swagger-ui
docker compose up -d swagger-ui
Open http://localhost:5555 (or your custom SWAGGER_UI_PORT). SWAGGER_API_URL must be reachable from inside the swagger-ui container, so if your spec is served by another Laradock container, use its container name (for example http://nginx/api/openapi.json) rather than localhost.
View logs
Useful when the UI shows a blank page or a spec fails to load:
- Laradock CLI
- Docker Compose
./laradock logs swagger-ui
docker compose logs --tail=100 swagger-ui
Keep the image up to date
Laradock builds Swagger UI FROM swaggerapi/swagger-ui:latest. Docker only pulls the latest tag the first time it's built, a plain rebuild reuses whatever was already pulled and won't fetch newer releases. To actually pull the newest upstream image and rebuild against it:
docker compose build --pull swagger-ui
Then start the container again with your normal ./laradock start swagger-ui (or docker compose up -d swagger-ui).
Common issues
- Still showing the default demo spec.
SWAGGER_API_URLonly takes effect on container start. Set it in.envand run./laradock restart swagger-uito apply it. - "Failed to fetch" when loading your spec. If your API lives in another Laradock container,
localhostfrom insideswagger-uirefers to theswagger-uicontainer itself, not your host or your API container. Use the API's container name instead (Laradock containers share thebackendnetwork). - CORS errors in the browser console. Swagger UI fetches the spec client-side from your browser, not just server-side, so your API must also send CORS headers allowing the origin
http://localhost:5555(or your custom port). - Port already in use on your host. Another service (or another Laradock project) is already bound to
5555. ChangeSWAGGER_UI_PORTin.envand restart with./laradock restart swagger-ui. - Image never picks up a newer Swagger UI release. See Keep the image up to date above,
latestis only resolved once unless you explicitly--pull.
Writing the spec by hand? See Swagger Editor. New to Laradock? Start at Getting Started.