[英]How do I pass a file into a Docker container to be used with the container?
I would like to pass a file from the host system to a container at runtime.我想在运行时将文件从主机系统传递到容器。 I want to run a CLI tool within a container and use the file as an argument to the CLI tool.
我想在容器中运行 CLI 工具并将该文件用作 CLI 工具的参数。 Is it possible to modify the following command:
docker run -it --rm --name <container-name>
to achieve what I want to do.是否可以修改以下命令:
docker run -it --rm --name <container-name>
来实现我想要做的。 The docker cp
command doesn't work for what I need since it doesn't run from within the container and I need to pass the file name as an argument. docker cp
命令不适用于我需要的东西,因为它不在容器内运行,我需要将文件名作为参数传递。
I usually use the -v "$PWD:$PWD" -w "$PWD"
trick.我通常使用
-v "$PWD:$PWD" -w "$PWD"
技巧。 Run container and volume mount the current host working directory into the container at the same path and set working directory to same path.运行 container 和 volume 将当前宿主机工作目录挂载到容器相同路径下,并将工作目录设置为相同路径。
So for example if I want to transcode a wav file on the host to a mp3 file usig ffmpeg running in a container I would do:因此,例如,如果我想将主机上的 wav 文件转码为在容器中运行的 mp3 文件 usig ffmpeg,我会这样做:
docker run --rm -v "$PWD:$PWD" -w "$PWD" mwader/static-ffmpeg:4.2.2 -i file.wav file.mp3
You can also add -u $UID:$GROUPS
if your unsure what default user the image runs as.如果您不确定图像运行的默认用户身份,您还可以添加
-u $UID:$GROUPS
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.