whenever I run a docker container, I want to send dynamic filename as some environment variable.
That is accessible in container so its printing its value when we 'echo'.
But ADD command not adding that file.
Dockerfile:
ADD $filename ./
echo ls # Not showing file
docker run -e filename='/path/to/file.extension'
Try using a volume instead:
$ echo "hello world" > somefile.txt
$ docker run -it --rm -v $PWD/somefile.txt:/data/somefile.txt alpine cat /data/somefile.txt
hello world
The Dockerfile lists the actions that occur when you run a "docker build". It's not possible to pass in an environment variable at run-time, because, at that point, the image is already built :-)
ADD
is run during compile (build) time. When you run docker exec -e
that is after the container has been built.
You cannot add dynamic files because it's compiled. The previous command about volumes is correct because you can provide those files ad-hoc during exec
and have your application pick them up.
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