将文件从主机复制到Docker容器 [英] Copying files from host to Docker container

查看:144
本文介绍了将文件从主机复制到Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我们合作的Docker容器构建一个备份和恢复解决方案。



我已经创建了Docker基础映像, ubuntu:base ,并且不希望每次使用Docker文件重建它,以便向其添加文件。



I要创建一个从主机运行的脚本,并使用 ubuntu:base Docker映像创建一个新的容器,然后将文件复制到该容器中。



如何将文件从主机复制到容器?

解决方案

cp 命令可用于此。例如:

  docker cp foo.txt mycontainer:/foo.txt 
docker cp mycontainer:/foo.txt foo.txt

参考: Docker CLI文档 cp


I am trying to build a backup and restore solution for the Docker containers that we work with.

I have Docker base image that I have created, ubuntu:base, and do not want have to rebuild it each time with a Docker file to add files to it.

I want to create a script that runs from the host machine and creates a new container using the ubuntu:base Docker image and then copies files into that container.

How can I copy files from the host to the container?

解决方案

The cp command can be used for that. For example:

docker cp foo.txt mycontainer:/foo.txt
docker cp mycontainer:/foo.txt foo.txt

Reference: Docker CLI docs for cp

这篇关于将文件从主机复制到Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆