Docker输入文件并保存在输出中 [英] Docker input file and save in output

查看:50
本文介绍了Docker输入文件并保存在输出中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个泊坞窗映像,该映像输入了本地文件,对其进行了一些处理,然后返回了本地保存的输出文件,但是它不起作用.如何允许本地用户输入文件,然后将输出保存在本地计算机上?

I built a docker image that inputs a local file, does some stuff to it, and returns an output file saved locally, but it does not work. How do I allow local, user input for files and then saving the output on the local machine?

我的Dockerfile看起来像这样:

My Dockerfile looks like this:

FROM python:3
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . /app
EXPOSE 5000
CMD [ "python", "process.py" ]

理想情况下,终端命令应该是这样的:

Ideally, the terminal command would be something like this:

docker run -p 5000:5000 [name of docker] [local path to input file] [local path to save output file]

我跑步时出现此错误:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"../test.flac\": stat ../test.flac: no such file or directory": unknown.

我该怎么做?

推荐答案

通常,docker容器无法闯入主机.

Generally, the docker container cannot break out into the host machine.

但是,您可以将主机上的本地目录挂载到容器中.在容器内部的挂载点中创建的文件在主机上也将可见.

However, you can mount a local directory from the host machine into the container. The files created in the mount point, inside the container, will also be visible on the host machine.

在下面的示例中,我从容器内的主机安装工作目录.我当前的目录包含一个输入文件.
容器 cat s 包含输入文件的内容,并将其附加到 output-file

In the example below I am mounting the working directory from the host machine inside the container. My current directory contains an input-file.
The container cats the content of the input-file and appends it to the output-file

// The initial wiorking directory content
.
└── input-file

// Run my dummy container and ask it to cat the content of the input file into the output file
docker run -v $(pwd):/root/some-path ubuntu /bin/bash -c "cat /root/some-path/input-file >> /root/some-path/output-file"

// The outcome
.
├── input-file
└── output-file

这篇关于Docker输入文件并保存在输出中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆