gpt4 book ai didi

docker - 如何将动态文件添加到docker容器

转载 作者:行者123 更新时间:2023-12-05 00:54:34 33 4
gpt4 key购买 nike

每当我运行 docker 容器时,我都想将动态文件名作为某个环境变量发送。

这可以在容器中访问,因此当我们“回声”时它会打印其值。

但是 ADD 命令没有添加那个文件。

Dockerfile:

ADD $filename ./
echo ls # Not showing file

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

最佳答案

尝试使用 volume反而:

$ echo "hello world" > somefile.txt
$ docker run -it --rm -v $PWD/somefile.txt:/data/somefile.txt alpine cat /data/somefile.txt
hello world

Dockerfile 列出了运行“docker build”时发生的操作。无法在运行时传入环境变量,因为此时镜像已经构建:-)

关于docker - 如何将动态文件添加到docker容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39821809/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com