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

FROM ubuntu:12.04

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

现在,我的主机中有一个名为abc.txt的文件。如何将其复制到此容器中。我可以在Dockerfile中添加从主机复制到容器的任何步骤吗?

最佳答案

像这样使用COPY命令:

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

official documentation中阅读有关COPY的更多详细信息

一种替代方法是使用ADD,但是如果您不想使用ADD的某些高级功能(如tar.gz文件的解压缩),那么这不是最佳实践。如果您仍然想使用ADD命令,请按以下步骤进行操作:
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

official documentation中阅读有关ADD的更多详细信息

07-24 15:28
查看更多