I am writing a dockerfile where i want to download a changing set of git repos: repo1, repo2, repo3. How should I supply these urls/strings to the dockerfile at image build or container run times?
I know one can pass an argument using the ARG
instruction and using
docker build --build-arg <var-name>=<value>
But what happens when I have a list of args of arbitrary length?
Thanks a lot.
You can pass environment variables with ENV declarations in a Dockerfile or with -e arguments to the docker run command. The following examples show ways to use environment variables.
If you want to pass multiple build arguments with docker build command you have to pass each argument with separate — build-arg. docker build -t <image-name>:<tag> --build-arg <key1>=<value1> --build-arg <key2>=<value2> .
If you want to pass variables through the docker-compose process into any of the Dockerfiles present within docker-compose. yml , use the --build-arg parameter for each argument to flow into all of the Dockerfiles.
The best I can think of is to pass in a comma-separated list:
docker build --build-arg repos=repo1,repo2
Docker won't parse this into a list for you, but the scripts run during the build could split the string into a list.
If you define your command using ENTRYPOINT
then any trailing parameters to docker run
get appended to the entry point command.
So if your Dockerfile contains:
ENTRYPOINT echo hello
Then:
docker run myimage glorious world
... will run the command
echo hello glorious world
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