This example show us how to copy a bash script into docker and execute it while building the docker image.

Bash script

This bash file just prints Hello but you can install packages with apt so on.

ubuntu@linux:~$ nano

set -e

echo "Hello"


ubuntu@linux:~$ nano Dockerfile

FROM ubuntu:16.04

RUN chmod +x / && /

CMD ["Finished!"]

Build image

ubuntu@linux:~$ docker build -t my_bash_image .

Sending build context to Docker daemon 16.9kB
Step 1/4 : FROM ubuntu:16.04
---> dd6f76d9cc90
Step 2/4 : COPY /
---> 999c8ab5eb6f
Step 3/4 : RUN chmod +x / && /
---> Running in cf67ddbfccf6
---> 8bf854a3e3e5
Removing intermediate container cf67ddbfccf6
Step 4/4 : CMD Finished!
---> Running in d16ca379f292
---> d0fd678a46df
Removing intermediate container d16ca379f292
Successfully built d0fd678a46df
Successfully tagged my_bash_image:latest