New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow files and paths to be ignored when uploading context #2224
Comments
@jellybob Why is the log dir in the same path as your source code ? Is it a problem to move the dir out? How does the CI server get code ? I guessing the fix for this is some type of |
This is fairly standard default behavior for web frameworks like this, so +1 for some method of ignoring specific files, even if it's just a "docker build" flag. |
As @tianon pointed out this is the default setup for Rails. In production we symlink that directory to somewhere more sensible, but running locally its nice to have everything self contained. The CI server obtains code by doing a git checkout, so wouldn't have all the logs sitting in the same directory, but I don't want to have to delete it every time I try building the image on my own machine to test changes. |
So, after thinking about it more, this can't be a "docker build" flag for the same reason we only have one such flag right now - it breaks repeatability. So if we add such functionality, it'll have to be a file, and I certainly can't think of a good name that's consistent with |
(but I do still agree we need this feature somehow!) |
I'd love to see this feature! I've been keeping a Dockerfile in the root of a project, because that is the sensible place for this project. It needs to load the project into the context. It bites though, because I'm using Git. So my entire git history gets loaded into the context. Not a dealbreaker, but it doesn't feel very clean. |
If we want this to be repeatable across builds, I'd argue the place for it is in the Dockerfile -- though that means the client needs to parse it and cooperate. I really like how this reads:
but a blacklist approach, a la .gitignore, would be way better for maintainability:
|
@vreon @tianon don't we already have this feature - what happens when you put a VOLUME ["log dir"] before you run? (I suspect this will need its own issue, but:
but if you add the VOLUME, you get something different?
it seems that the ADD statement gets added to the underlying image, whereas the output of RUN goes into the VOLUME, and thus is not contained in the pushed image - see https://index.docker.io/u/svendowideit/test-volume/ |
Ok, let me paint a better picture. You've got a huge ruby on rails application, and you've been developing on it for a while, which involves running it and testing against it frequently. At this point, your application directory has a "log" folder in it that contains a very large development.log file. When you "docker build", you now get to wait while that "development.log" file gets uploaded to the backend, even though you're not going to want it included it in the image. Another great example would be the associated SQLite database for that same application. Since you've been doing development, it's bloated with a lot of very large records so that you can easily test against many different scenarios. It is just a test database however, so you don't include it in your Docker image and you just get to suffer while it's uploaded, or move it outside the context temporarily every time you want to build (which can be even more annoying than just waiting, IMO). |
mmm, that means the client needs to parse the Dockerfile - perhaps we should collect reasons / use cases that would benefit from that change. or could this be a I'll move my VOLUME/ADD quandry to another issue. |
I'd be fine with an |
Really new to docker, but this issue caught my eye. We are rolling up a project managed in git with many submodules. Looking at 300mb of source code and assets, but 1.1GB of .git object graphs/data. Definitely don't need those in the docker context. My suggestion is a .dockerignore file, mirroring how git does it. The work around for us right now will probably be a clean checkout, fetch the submodules and then clean out all the .git directories. |
I totally agree with a |
Looks like archive/archive supports passing an exclude list. I'll write up a simple dirty line reader and pass those along to the initial context Tar file creation. dives in |
+1, a |
Sorry about the noise, patch should be pretty close. |
+1 for this solution. $ docker build danhixon/rails-app . YIKES! |
Fixes moby#2224 Docker-DCO-1.1-Signed-off-by: Travis Cline <travis.cline@gmail.com> (github: tmc)
+1. In the meantime I'm going to try @disposable-ksa98 's context/ folder for a new project. |
PS: in the end I have put the Dockerfile and all its context in ./docker, and I run
Now "Uploading context" takes a fraction of a second, instead of more than a minute. It seems to work alright. Let me know if there's reasons why it would be a bad thing to do. |
It's not bad, but when you copy files into the context as part of a On Saturday, 14 June 2014, Pierre Masci notifications@github.com wrote:
|
👍 for this feature! |
+1 for this too. We could exclude a python virtual environment when uploading the context with that feature ! |
+1 this is really important, uploading logs and .git folders on every build makes it terrible, unless you end up restructuring your project folders to workaround this. |
Being notified again because of a +1, here is a workaround (mentioned before). It's rather trivial to use a Makefile or another build tool for this:
Then This also allows you to use a template for the Dockerfile, e.g. just via You could then also use a stamp file (instead of the phony target) and define your input files as prerequisites for it, allowing you to only (re)build the docker image if files have changed. |
I understand the workaround. The +1 is here to get this feature included without having to modify our currently directories structure or using the trick you provide just to build the image |
Fixes moby#2224 Docker-DCO-1.1-Signed-off-by: Travis Cline <travis.cline@gmail.com> (github: tmc)
Thanks ! |
Is it possible to docker ignore something like all of the pyc files in all subdirs? I did *.pyc but it only ignores the files i nthe top level directory. |
@shuhaowu Yeah, you are right. Pretty annoying.
Only this way now :( |
Does */.pyc work? |
Nope. |
Unfortunately the simple functionality to ignore is a pure pass through to tar, so smart matchers from VCS’s won’t work. For more reference, look at the tar man page here: http://www.gnu.org/software/tar/manual/html_node/exclude.html Notably, tar supports matching VCS pattern files but you have to explicitly tell it which kind.Sent from a hot air balloon On Mon, Sep 8, 2014 at 7:32 AM, Paweł Stiasny notifications@github.com
|
I always liked how mercurial included a syntax line that allowed either glob or regexp syntax. Perhaps there could be a line in the docker ignore that selected which tar VCS ignore format to expect. |
This is actually using Go's glob support (see |
Following @interlock's suggestion, my workaround is tarball the code, making use of tar's much better exclude support, and ADD the tarball in the Dockerfile (which automatically extracts), i.e. https://gist.github.com/synotna/6c2ea7e4350160b22748 |
@synotna what version of docker are you using. I believe 1.4.1 and up have tar style ignores with .dockerignore. If you are stuck in a docker version lower than that, the tar method works great. You can also stream the tar in to docker build using
Or something along those lines. |
antony@do:~/docker-testing$ docker --version antony@do:~/docker-testing$ find | grep ".pyc" DockerfileFROM python:3.4.3
RUN mkdir -p /var/app/
WORKDIR /var/app/
ADD . . .dockerignore*.pyc antony@do: Dockerfile-tarFROM python:3.4.3
RUN mkdir -p /var/app/
WORKDIR /var/app/
ADD docker.tar . .gitignore
tar --exclude-from=.gitignore -cvf docker.tar . |
@synotna If you must use the .gitignore, then thats the path you must take. If you don't mind copying/symlinking that .gitignore to .dockerignore you can save some commands. |
? My point is, .dockerignore is not as effective as .gitignore as it does not recurse subdirectories The .dockerignore file only ignored one level of pyc file, .gitignore (which works with tar --exclude-from-file) ignored all levels |
@synotna FYI you can now specify recursive patterns in .dockerignore edited |
Awesome to hear, thanks! |
I'm attempting to Dockerize a fairly large Rails application, with the intent that during development I can just run
docker build
locally, while for deployment the CI server will do so.In either case though it currently picks up things like the
log
directory, which can grow to several gigabytes of large files which I'm never going to want included in an image.Is it possible to tell Docker to ignore that directory when uploading the build context? If not, what would be involved in making it happen? I've never used Go, but given a pointer in the right direction I'm happy to give it a shot.
The text was updated successfully, but these errors were encountered: