#!/usr/bin/env bash set -e # wrapper around "docker build" that creates a temporary directory and copies files into it first so that arbitrary host directories can be copied into containers without bind mounts, but accepts a Dockerfile on stdin # usage: ./docker-build.sh some-host-directory some-new-image:some-tag < "$tmp/Dockerfile" from="$(awk -F '[ \t]+' 'toupper($1) == "FROM" { print $2; exit }' "$tmp/Dockerfile")" if ! docker inspect "$from" &> /dev/null; then docker pull "$from" > /dev/null fi cp -RL "$dir" "$tmp/dir" error="$(command docker build -t "$imageTag" "$tmp" 2>&1)" || { echo "$error" >&2; exit 1; }