Is it possible to create Dockerfile
that executes a command on host when image is being build?
Now I'm doing:
./script_that_creates_magic_file.sh docker build .
with Dockerfile:
FROM alpine COPY magic_file
I want to be able to do:
docker build .
with Dockerfile:
FROM alpine # invoke script_that_creates_magic_file.sh on the host COPY magic_file
Of course, this script is in the same directory as Dockerfile.
(Just a suggestion)
We usually have the following structure for building our docker images:
my-image/ ├── assets │ ├── entrypoint.sh │ └── install.sh ├── build.sh ├── Dockerfile ├── README.md └── VERSION
script_that_creates_magic_file.sh
. Other common tasks involve downloading required files or temporarily copying ssh keys from the host. Finally, this script will call docker build .
install.sh
RUN
I find the above structure convenient and self-documented since everyone in the team can build any image (no special instructions/steps). The README is there to explain what the image is doing... but I won't lie to you... it is usually empty... (or has an h1
for the gitlab to display) :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With