简体   繁体   English

如何将文件从 docker 图像移动到计算机上的文件夹中

[英]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

You can find more information in here您可以在此处找到更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 SFTP 服务器获取文件并将它们移动到 bash 脚本中的另一个文件夹? - How do I get the files from SFTP server and move them to another folder in bash script? 如何使用find和xargs将文件从一个文件夹中的一个文件夹移动到另一个文件夹? - How do you use find and xargs to move files from a folder within a folder to another folder? 如何使用scp将文件从远程计算机(运行Linux)复制到Windows计算机? - How do I copy files from a remote computer (running Linux) to my Windows computer using scp? 如何对目录中的所有文件执行命令,并将每个文件的输出移至新文件夹? - How do I conduct a command on all the files in a directory and move the output for each file to a new folder? 如何从大型 Dropbox 文件夹下载文件? - How do I download files from a large dropbox folder? 如何将文件从一个文件夹移动到另一个在特定日期创建的文件夹,给出 redhat 中的创建日期 - How can I move files from one folder to another created at specific date giving the creation date in redhat 如何从 Google Collab 移动 Drive 文件夹中的文件? - How to move files on Drive folder from Google Collab? 如何使用Docker映像构建应用程序? - How do I build an application with a docker image? 如何创建可分发的 Docker 映像? - How do I create a distributable Docker image? 除了某些文件夹中的文件外,我如何将其所有文件包含在文件夹或目录中? - How do I tar a folder or directory with all of it's files except leave out files from certain folders?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM