#!/bin/bash # get the image name from the current working directory IMG_NAME=$(basename $(pwd)) # create a random container name and use throuout this scrip CNTR=$(date | md5sum | head -c 10) docker build -t $IMG_NAME . # create container without running it docker create --name $CNTR $IMG_NAME # copy the file to working directory of the host docker cp $CNTR:/mydata/greetings.txt . # remove container again docker rm $CNTR # now list new file ls -l greetings.txt