Dockerfile拷贝保持子目录结构 [英] Dockerfile copy keep subdirectory structure

查看:26
本文介绍了Dockerfile拷贝保持子目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些文件和文件夹从我的本地主机复制到一个 docker 映像构建中.

I'm trying to copy a number of files and folders to a docker image build from my localhost.

文件是这样的:

folder1
    file1
    file2
folder2
    file1
    file2

我正在尝试制作这样的副本:

I'm trying to make the copy like this:

COPY files/* /files/

但是,所有文件都放在/files/中,Docker 中有没有办法保留子目录结构以及将文件复制到它们的目录中?

However, all files are placed in /files/ is there a way in Docker to keep the subdirectory structure as well as copying the files into their directories?

推荐答案

使用这个 Dockerfile 从 COPY 中移除星标:

Remove star from COPY, with this Dockerfile:

FROM ubuntu
COPY files/ /files/
RUN ls -la /files/*

结构在那里:

$ docker build .
Sending build context to Docker daemon 5.632 kB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu
 ---> d0955f21bf24
Step 1 : COPY files/ /files/
 ---> 5cc4ae8708a6
Removing intermediate container c6f7f7ec8ccf
Step 2 : RUN ls -la /files/*
 ---> Running in 08ab9a1e042f
/files/folder1:
total 8
drwxr-xr-x 2 root root 4096 May 13 16:04 .
drwxr-xr-x 4 root root 4096 May 13 16:05 ..
-rw-r--r-- 1 root root    0 May 13 16:04 file1
-rw-r--r-- 1 root root    0 May 13 16:04 file2

/files/folder2:
total 8
drwxr-xr-x 2 root root 4096 May 13 16:04 .
drwxr-xr-x 4 root root 4096 May 13 16:05 ..
-rw-r--r-- 1 root root    0 May 13 16:04 file1
-rw-r--r-- 1 root root    0 May 13 16:04 file2
 ---> 03ff0a5d0e4b
Removing intermediate container 08ab9a1e042f
Successfully built 03ff0a5d0e4b

这篇关于Dockerfile拷贝保持子目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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