Docker input file and save in output(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?
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]
When I run, I get this error:
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.
How can I do this?
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.
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 cat
s 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 输入文件并保存在输出中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Docker 输入文件并保存在输出中


基础教程推荐
- 在 Python 中将货币解析为数字 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01