I'm trying to tag and push all my docker files into azure container repository by using bash script:
path="./base-images"
dfname="test.azurecr.io"
for file in $path; do
docker build . -t $dfname -f $file
docker push $dfname/baseimage/
done
but I got an error:
failed to solve with frontend dockerfile.v0: failed to read dockerfile: read /var/lib/docker/tmp/buildkit-mount173864107/base-images: is a directory
invalid reference format
Why does it write a different path? All my docker files are inside another folder (base-images).
Your
for file in $pathis not giving you the individual files in that directory, which is what it looks like you're hoping for. It is just going to assign the one value bash sees (./base-images) to$fileand give you one iteration based on that. That's why docker complains aboutbase-images: is a directory: it is expecting aDockerfilefile, not a directory.To get bash to loop through all of the files in that directory you need to follow this answer from a few years ago and start with
I would also suggest calling your
$pathvariable$diror$directoryso you're not confusing other maintainers of this code with the$PATHbuiltin variable.Shellcheck would also tell you to put your variables in quotes such as: