How to add dynamic file to docker container

whenever I start the docker container, I want to send the dynamic file name as some environment variable.

It is available in the container, so it prints its value when we echo.

But the ADD command does not add this file.

Dockerfile:

ADD $filename ./
echo ls # Not showing file

docker run -e filename = '/path/to/file.extension'

+4
source share
3 answers

Try instead of volume :

$ 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 Docker Build. It is not possible to pass an environment variable at runtime because at this point the image is already plotted :-)

+2
source

"".

docker-compose.yml ( , ).

mysql:
  image: mysql
  volumes:
    - /someLocalFolder/lib/mysql/:/var/lib/mysql

, , , ..

+1

ADDruns at compile time (build). When you start docker exec -ewhich after the container is assembled.

You cannot add dynamic files because they are compiled. The previous volumes command is correct because you can provide these ad-hoc files at the time execand attach your application.

0
source

Source: https://habr.com/ru/post/1656531/


All Articles