docker - Equivalent of --env-file for build-arg? - TagMerge
6Equivalent of --env-file for build-arg?Equivalent of --env-file for build-arg?

Equivalent of --env-file for build-arg?

Asked 10 months ago
4
6 answers

There's no such an option, at least for now. But if you have too many build args and want to save it in a file, you can archive it as follows:

  1. Save the following shell to buildargs.sh, make it executable and put it in your PATH:

    #!/bin/bash
    awk '{ sub ("\\\\$", " "); printf " --build-arg %s", $0  } END { print ""  }' $@
    
  2. Build your image with argfile like:

    docker build $(buildargs.sh argfile) -t your_image .
    

Source: link

0

This code is safe for build-arg's that contain spaces and special characters:

for arg in buildarg1 buildarg2 ; do opts+=(--build-arg "$arg") ; done

...

docker run ... "${opts[@]}"

Just substitute buildarg1 and so on with your build-arg's escaped.

Source: link

0

Using linux you can create a file (example: arg_file) with the variables declared:

ARG_VAL_1=Hello
ARG_VAL_2=World

Execute the source command on that file:

source arg_file

Then build a docker image using that variables run this command:

docker build \
  --build-arg "ARG_VAL_1=$ARG_VAL_1" \
  --build-arg "ARG_VAL_2=$ARG_VAL_2" .

Source: link

0

$ docker build [OPTIONS] PATH | URL | -
$ docker build https://github.com/docker/rootfs.git#container:docker
$ docker build http://server/context.tar.gz
$ docker build - < Dockerfile
Get-Content Dockerfile | docker build -

Source: link

0

Save the following shell to buildargs.sh, make it executable and put it in your PATH:
#!/bin/bash
awk '{ sub ("\\\\$", " "); printf " --build-arg %s", $0  } END { print ""  }' [email protected]
Build your image with argfile like:
docker build $(buildargs.sh argfile) -t your_image .

Source: link

0

Save the following shell to buildargs.sh, make it executable and put it in your PATH:
#!/bin/bash
awk '{ sub ("\\\\$", " "); printf " --build-arg %s", $0  } END { print ""  }' [email protected]
Build your image with argfile like:
docker build $(buildargs.sh argfile) -t your_image .

Source: link

Recent Questions on docker

    Programming Languages