From 9a5ccc70e3e1ed8e8cda5450a23b5552f2a2092f Mon Sep 17 00:00:00 2001 From: Oliver Giles Date: Fri, 4 Jun 2021 10:12:59 +1200 Subject: [PATCH] add example script for docker builds --- UserManual.md | 2 ++ examples/docker-advanced.sh | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 examples/docker-advanced.sh diff --git a/UserManual.md b/UserManual.md index c9151e3..588ae34 100644 --- a/UserManual.md +++ b/UserManual.md @@ -588,6 +588,8 @@ docker run --rm -ti -v $PWD:/root ubuntu /bin/bash -xe <<(:) # get a new pipe +docker build - <<\EOF | + FROM debian:bullseye + RUN apt-get update && apt-get install -y build-essential +EOF +tee >(awk '/Successfully built/{print $3}' >&$pfd) # parse output to pipe +read tag <&$pfd # read tag back from pipe +exec {pfd}<&- # close pipe + +# Alternatively, you can use the -t option to docker build +# to give the built image a name to refer to later. But then +# you need to ensure that it does not conflict with any other +# images, and handle cases where multiple instances of the +# job attempt to update the tagged image. + +# If you want the image to be cleaned up on exit: +trap "docker rmi $tag" EXIT + +# Now use the image to build something: +docker run -i --rm \ + -v "$PWD:$PWD" \ + -w "$PWD" \ + -u $(id -u):$(id -g) \ + $tag /bin/bash -eux \ +<