Home > OS >  push all dockerfiles to acr using bash
push all dockerfiles to acr using bash

Time:08-12

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).

CodePudding user response:

Can you provide more information on your Dockerfile name? What is $file? This answer indicates you might need to capitalize the "D" in dockerfile. Again, can't answer fully without more info

CodePudding user response:

Your for file in $path is 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 $file and give you one iteration based on that. That's why docker complains about base-images: is a directory: it is expecting a Dockerfile file, 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

for file in "$path"/*; do

I would also suggest calling your $path variable $dir or $directory so you're not confusing other maintainers of this code with the $PATH builtin variable.

Shellcheck would also tell you to put your variables in quotes such as:

docker build . -t "$dfname" -f "$file"
  • Related