Skip to content

Instantly share code, notes, and snippets.

@synotna
Last active November 22, 2015 13:39
Show Gist options
  • Save synotna/6c2ea7e4350160b22748 to your computer and use it in GitHub Desktop.
Save synotna/6c2ea7e4350160b22748 to your computer and use it in GitHub Desktop.
How to use .gitgnore for Dockerfile because .dockerignore sucks

Want to exclude patterns of files at any folder depth?

Pulling your hair out because .dockerignore (Go filepath.Match) sucks?

Don't waste time with .dockerignore

Make use of tar's pattern matching together with Docker's tar support and save your sanity!

# docker-build.sh
#!/bin/bash
# Where code is the folder containing your code
tar --exclude-from=.gitignore -C code -cvf docker.tar .
docker build -t my-image .
FROM baseimage
# Docker automagically extracts tars using the ADD instruction
ADD docker.tar .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment