Overriding SWAGGER_JSON and URL does not work for Docker distribution
See original GitHub issueContext
- 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:
- Created 5 years ago
- Reactions:12
- Comments:11 (3 by maintainers)
Top GitHub Comments
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.I have a swagger.json on my desktop, so running this command worked:
localhost:9000
is loading correct file.