Skip to content

Instantly share code, notes, and snippets.

@luisnquin
Created November 26, 2022 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisnquin/26a005577151f11eda13de74ab0fc6cb to your computer and use it in GitHub Desktop.
Save luisnquin/26a005577151f11eda13de74ab0fc6cb to your computer and use it in GitHub Desktop.
Bash script that runs swagger-editor in docker and waits for signal SIGINT to kill and remove containers
main() {
docker_command="docker run -d -p 80:8080 "
if [[ $1 != "" ]]; then
absolute_path=$(realpath "$1")
dir=$(dirname "$absolute_path")
docker_command+="-v $dir:/tmp -e SWAGGER_FILE=/tmp/$1 "
fi
docker_command+="swaggerapi/swagger-editor"
container_id=$(eval "$docker_command")
echo "Listening here: \033[1;34mhttp://localhost\033[0m 🍁"
(
trap exit SIGINT
read -r -d '' _ </dev/tty
)
docker kill "$container_id" >/dev/null
docker rm "$container_id" >/dev/null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment