Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Last active April 30, 2020 04:27
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 ORESoftware/8b0408b56d17fdc4e26c5d10ea3b7199 to your computer and use it in GitHub Desktop.
Save ORESoftware/8b0408b56d17fdc4e26c5d10ea3b7199 to your computer and use it in GitHub Desktop.
Build and run docker image/container
#!/usr/bin/env bash
# the nice thing about this script is it will remove
# existing containers in the background
# while the new image is being built
set -eo pipefail
cd "$(dirname "$BASH_SOURCE")"
(
set +e;
docker stop "local-test"
docker rm "local-test"
) &
commit_id="$(git rev-parse HEAD)"
docker build --build-arg commit_id="$commit_id" -t "local-test" .
wait; # wait for previous containers to be removed
docker run --rm -ti --name "local-test-c" "local-test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment