我构建了一个输入本地文件的 docker 镜像,对其执行一些操作,并返回本地保存的输出文件,但它不起作用。如何允许本地用户输入文件,然后将输出保存在本地机器上?
我的 Dockerfile 看起来像这样:
FROM python:3
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . /app
EXPOSE 5000
CMD [ "python", "process.py" ]
理想情况下,终端命令应该是这样的: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 容器无法突破到宿主机。
但是,您可以将本地目录从主机挂载到容器中。在容器内的挂载点中创建的文件也将在主机上可见。
在下面的示例中,我从容器内的主机安装工作目录。我当前的目录包含一个 input-file
。
容器 cat
s input-file
的内容并将其附加到 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
关于python - Docker 输入文件并保存在输出中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63400807/