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

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

问题描述

我试图为我们使用的docker容器建立一个备份和恢复解决方案。



我已经创建了Docker基础镜像 ubuntu:base ,并且不想每次使用dockerfile重建它以添加文件。



一个从主机运行的脚本,使用 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 dockerfile 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. But I am stuck copy files on the 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天全站免登陆