Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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