如何在Dockerfile中添加诸如.git之类的隐藏目录的所有文件/目录 [英] How to ADD all files/directories except a hidden directory like .git in Dockerfile
问题描述
我们经常做的一件事是在我们构建一个Docker图像时将所有源代码打包在 Dockerfile
pre> 添加。 / app
我们如何避免包含 .git
目录以简单的方式?
我尝试使用Unix的方式来处理这个使用添加[^。] * / app /
完整示例:
docker @ boot2docker:/ mnt / sda1 / tmp / abc $ find。
。
./c
./.git
./Dockerfile
./good
./good/a1
docker @ boot2docker:/ mnt / sda1 / tmp / abc $ cat Dockerfile
从ubuntu
添加[^。] * / app /
docker @ boot2docker:/ mnt / sda1 / tmp / abc $ docker build - t abc。
发送构建上下文到Docker守护进程4.096 kB
发送构建上下文到Docker守护程序
步骤0:FROM ubuntu
---> 04c5d3b7b065
步骤1:ADD [^ 。] * / app /
d ---> 5d67603f108b
删除中间容器60159dee6ac8
成功构建5d67603f108b
docker @ boot2docker:/ mnt / sda1 / tmp / abc $ docker run - it abc
root @ 1b1705dd66a2:/#ls -l app
total 4
-rw-r - r-- 1 1000 staff 30 Jan 22 01:18 Dockerfile
- rw-r - r-- 1 root root 0 Jan 22 01:03 a1
-rw-r - r-- 1 root root 0 Jan 22 00:10 c
其次,它将丢失目录结构,因为 good \a1
更改为 a1
。
Docker中的相关源代码是 https://github.com/docker/docker/blob/eaecf741f0e00a09782d5bcf16159cc8ea258b67/builder/internals.go#L115
您可以在。dockerignore文件
One of things we do often is to package all source code in Dockerfile
when we build a Docker image.
ADD . /app
How can we avoid including the .git
directory in simple way ?
I tried the Unix way of handling this using ADD [^.]* /app/
Complete sample:
docker@boot2docker:/mnt/sda1/tmp/abc$ find . . ./c ./.git ./Dockerfile ./good ./good/a1 docker@boot2docker:/mnt/sda1/tmp/abc$ cat Dockerfile FROM ubuntu ADD [^.]* /app/ docker@boot2docker:/mnt/sda1/tmp/abc$ docker build -t abc . Sending build context to Docker daemon 4.096 kB Sending build context to Docker daemon Step 0 : FROM ubuntu ---> 04c5d3b7b065 Step 1 : ADD [^.]* /app/ d ---> 5d67603f108b Removing intermediate container 60159dee6ac8 Successfully built 5d67603f108b docker@boot2docker:/mnt/sda1/tmp/abc$ docker run -it abc root@1b1705dd66a2:/# ls -l app total 4 -rw-r--r-- 1 1000 staff 30 Jan 22 01:18 Dockerfile -rw-r--r-- 1 root root 0 Jan 22 01:03 a1 -rw-r--r-- 1 root root 0 Jan 22 00:10 c
And secondly, it will lose the directory structure, since good\a1
gets changed to a1
.
Related source code in Docker is https://github.com/docker/docker/blob/eaecf741f0e00a09782d5bcf16159cc8ea258b67/builder/internals.go#L115
You may exclude unwanted files with the help of the .dockerignore file
这篇关于如何在Dockerfile中添加诸如.git之类的隐藏目录的所有文件/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!