如何解决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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。