简体   繁体   English

如何将文件传递到 Docker 容器中以与容器一起使用?

[英]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.

相关问题 如何将配置文件传递给 docker 容器? - How do i Pass a config file to a docker container? Docker:如何删除用于构建容器的所有映像? - Docker: How Do I remove all images used to build a container? 如何将参数传递给Docker容器并使用传递的参数更新容器中的文件 - How to pass parameter into docker container and update file in container with passed parameter 如何从Docker容器中看到另一个Docker容器? - From a docker container how do I see another docker container? 我 shell 到 Docker 容器后如何编辑文件? - How do I edit a file after I shell to a Docker container? 如何在Docker容器中使用Ruby编写文件? - How do I write a file with Ruby within a Docker container? 如何在 selenium docker 容器中找到下载文件位置? - How do I find download file location in selenium docker container? 如何在Kubernetes中将作为环境变量的Docker映像摘要传递给容器 - How to pass as environment variable the digest of the Docker image used to the container, in Kubernetes 如何连接到docker容器的localhost(从容器内部) - How do I connect to the localhost of a docker container (from inside the container) 如何将 docker 容器端口暴露给另一个容器 - How do I expose a docker container port to another container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM