I have a Dockerfile that needs to run a bash script before building.
Dockerfile:
ARG IMAGE_VERSION
FROM path_to_image/images/base:${IMAGE_VERSION}
CMD /code/run-app
The script will find the latest image version by scraping a website. I can't use the "latest" key word as the images are not hosted on docker hub. I need the IMAGE_VERSION to be equal to the output of a script before running the docker build command?
CodePudding user response:
You could run sed before building the image
sed -i "s/^FROM.*$/FROM path_to_image\/images\/base:$(command)/" Dockerfile
CodePudding user response:
Assuming your script outputs the tag you need, you can do something like this (assuming your script is called myscript.sh)
docker build --build-arg IMAGE_VERSION=$(./myscript.sh) -t myimage .