Skip to content

Instantly share code, notes, and snippets.

@nfultz
Created June 19, 2017 20:38
Show Gist options
  • Save nfultz/7a949aa813312dda3ab05305f830d11b to your computer and use it in GitHub Desktop.
Save nfultz/7a949aa813312dda3ab05305f830d11b to your computer and use it in GitHub Desktop.
Comments on working around .git folder in docker.

Here is an attempt at working around adding .git into dockers accidentally, an issue you saw earlier.

Docker is written in go and supports some wildcards in the ADD command. https://stackoverflow.com/questions/26591862/using-docker-add-command-for-multiples-files links to: https://golang.org/src/path/filepath/match_test.go

Putting that together,

nfultz@nfultz:dockertest$tree -a
.
├── 1
├── 2
├── .5
├── a
│   └── 3
├── b
│   └── 4
└── Dockerfile

2 directories, 6 files
nfultz@nfultz:dockertest$cat Dockerfile 
FROM ubuntu:latest

ADD [^.]* /root/


nfultz@nfultz:dockertest$docker build -t test:wildcard .
Sending build context to Docker daemon  5.632kB
Step 1/2 : FROM ubuntu:latest
 ---> 7b9b13f7b9c0
Step 2/2 : ADD [^.]* /root/
 ---> Using cache
 ---> b5ef390c2c49
Successfully built b5ef390c2c49
Successfully tagged test:wildcard
nfultz@nfultz:dockertest$docker run -it test:wildcard /bin/bash
root@b0f879353d4c:/# ls -latr /root/
total 20
-rw-r--r--  1 root root  148 Aug 17  2015 .profile
-rw-r--r--  1 root root 3106 Oct 22  2015 .bashrc
-rw-rw-r--  1 root root    0 Jun 19 20:28 1
-rw-rw-r--  1 root root    0 Jun 19 20:28 2
-rw-rw-r--  1 root root    0 Jun 19 20:28 3
-rw-rw-r--  1 root root    0 Jun 19 20:28 4
-rw-rw-r--  1 root root   39 Jun 19 20:34 Dockerfile
drwx------  2 root root 4096 Jun 19 20:34 .
drwxr-xr-x 35 root root 4096 Jun 19 20:34 ..

Above, you can see that infact .5 was not added into the docker.

@nfultz
Copy link
Author

nfultz commented Jun 19, 2017

Strangely, the extra folders were stripped out. Trying to make a v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment