Reputation: 1286
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'
Upvotes: 7
Views: 12738
Reputation: 4880
to add to Mark's answer.
If you want to use a docker-compose.yml file (a good idea if youre planning on running the container over and over).
mysql:
image: mysql
volumes:
- /someLocalFolder/lib/mysql/:/var/lib/mysql
you can add as many volumes as you like this way, including individual files which can be handy for config etc.
Upvotes: 1
Reputation: 4012
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.
Upvotes: 1
Reputation: 78021
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 :-)
Upvotes: 3