question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overriding SWAGGER_JSON and URL does not work for Docker distribution

See original GitHub issue

Context

  • OS: Alpine (Docker)
  • Browser: any
  • Method of installation: Docker
  • Swagger-UI version: 3.20.X and 3.21.X at least
  • Swagger/OpenAPI version: any

SWAGGER_JSON environment variable ignored by Docker deployment

The Docker build of swaggerapi/swagger-ui does not work when overriding the SWAGGER_JSON with a mounted file as documented in https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/installation.md.

run.sh updates the nginx index.html if a mounted file $SWAGGER_JSON exists.

if [[ -f $SWAGGER_JSON ]]; then
  cp -s $SWAGGER_JSON $NGINX_ROOT
  REL_PATH="./$(basename $SWAGGER_JSON)"
  sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE
  sed -i "s|http://example.com/api|$REL_PATH|g" $INDEX_FILE
fi

Problem is that the base image used by swaggerapi/swagger-ui - FROM nginx:1.15-alpine - has a index.html.gz file which takes precedence over the index.html, so the updated index.html is ignored.

To reproduce:

Have your swagger.json in /bar

docker pull swaggerapi/swagger-ui docker run -p 80:8080 -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo swaggerapi/swagger-ui

Access swagger-ui @ http://<machine>/

Will see petstore, not your swagger.json.

URL environment variable ignored by Docker deployment

To reproduce:

Have your swagger.json in http://<machine>/swagger.json

docker pull swaggerapi/swagger-ui docker run -p 80:8080 -e URL=“http://<machine>/swagger.json” swaggerapi/swagger-ui

Access swagger-ui @ http://<machine>/

Will see petstore, not http://<machine>/swagger.json.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
xshrimcommented, Jul 10, 2019

you should use API_URL, not SWAGGER_JSON. example: docker run -it -e API_URL=http://192.168.43.103:9090/swagger.json -p 8081:8080 swaggerapi/swagger-ui 192.168.43.103 is host ip.

2reactions
sitetestercommented, Sep 24, 2019

I have a swagger.json on my desktop, so running this command worked:

docker run -p 9000:8080 -e SWAGGER_JSON=/mnt/swagger.json -v ~/Desktop:/mnt swaggerapi/swagger-ui

localhost:9000 is loading correct file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installation - Swagger Documentation
The base URL of the web application can be changed by specifying the BASE_URL environment variable: docker run -p 80:8080 -e BASE_URL=/swagger -e...
Read more >
Swagger running with local json file in Docker Image
I have a swagger.json on my desktop so running this command worked docker run -p 9000:8080 -e SWAGGER_JSON=/mnt/swagger.json -v ~ ...
Read more >
HTTP API V2 - Docker Documentation
This specification covers the URL layout and protocols of the interaction between docker registry and docker core. This will affect the docker core...
Read more >
Metadata and Docs URLs - FastAPI
This is the version of your own application, not of OpenAPI. For example 2.5.0 . terms_of_service, str, A URL to the Terms of...
Read more >
Build and run an ASP.NET Core app in a container
We will not use Docker Compose in this tutorial, so both "Yes" and "No" answers are fine. Change the port for application endpoint...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found