[英]How do i move files from a docker image into a folder on the computer
I'm building a docker image which I need to copy a file added to the image into a write-protected location on a Linux machine (/opt).我正在构建一个 docker 图像,我需要将添加到该图像的文件复制到 Linux 机器 (/opt) 上的写保护位置。
so far I have tried doing this by adding the file to the docker image and then using a cp command to move it into /opt as shown below:到目前为止,我已经尝试通过将文件添加到 docker 图像然后使用 cp 命令将其移动到 /opt 来执行此操作,如下所示:
FROM ubuntu:latest
ADD test.txt /
CMD ["cp", "./test.txt", '/opt']
this doesn't work at all even when trying to move the file just into the desktop so I would appreciate at explanation about how to do it properly.即使试图将文件移动到桌面上,这也根本不起作用,所以我将不胜感激解释如何正确地做到这一点。
It looks like you need to share a volume between the container and the host.看起来您需要在容器和主机之间共享一个卷。
If that is the case probably your best approach is to create a docker compose file, similar to the one below.如果是这种情况,您最好的方法可能是创建一个 docker 撰写文件,类似于下面的文件。
---
version: "3.3"
services:
fileserver:
image: "your-docker-image"
volumes:
- /opt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.