Last active
October 24, 2022 13:17
-
-
Save gwpl/badde4515f383665da640a2c6f98ff7a to your computer and use it in GitHub Desktop.
docker-run.sh - run command in docker just based on Dockerfile (no need for naming image etc - script uses hash of generated image)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://gist.github.com/gwpl/badde4515f383665da640a2c6f98ff7a | |
# | |
# In directory with Dockerfile , you just use : | |
# $ docker-run.sh command... | |
# to run command inside dockerfile. Image hash etc will be automatically identified. | |
if [ -z "$0" ]; then | |
cat <<E | |
Run command in docker just based on Dockerfile (no need for naming image etc - script uses hash of generated image) | |
This script runs provided command with bash shell in container build with Dockerfile in current directory. | |
This is convenient to just run commmand inside, e.g. ls, or any other, without tagging, naming container. | |
Script just gets resulting hash (last past of 'docker build .' output) of build and uses it to identify image. | |
E | |
exit 0 | |
fi | |
#set -x | |
# get image hash (or tag it if you prefer) | |
image_hash="$(docker build .|tail -n 1|awk '{print $NF}')" | |
# and run lints: | |
docker run $image_hash bash -c "${*}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment