如何使用 Dockerfile 将文件从主机复制到容器 [英] How to copy file from host to container using Dockerfile

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

问题描述

我写了一个看起来像这样的 Dockerfile

I have written a Dockerfile which looks like this

FROM ubuntu:12.04

RUN apt-get update
RUN apt-get install -y wget

现在我的主机中有一个名为 abc.txt 的文件.我怎样才能将它复制到这个容器.我可以在 Dockerfile 中添加从主机复制到容器的任何步骤.

Now I'm having a file called abc.txt in my host machine. How can I copy it to this container. Is there any step that I can add in Dockerfile which copy from Host to Container.

推荐答案

像这样使用 COPY 命令:

Use COPY command like this:

COPY foo.txt /data/foo.txt
# where foo.txt is the relative path on host
# and /data/foo.txt is the absolute path in the image

官方文档

另一种方法是使用 ADD,但如果您不想使用 ADD 的某些高级功能(例如解压缩 tar.gz 文件),这不是最佳做法.如果您仍想使用 ADD 命令,请这样做:

An alternative would be to use ADD but this is not the best practise if you dont want to use some advanced features of ADD like decompression of tar.gz files.If you still want to use ADD command, do it like this:

ADD abc.txt /data/abc.txt
# where abc.txt is the relative path on host
# and /data/abc.txt is the absolute path in the image

官方文档

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

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