How to include local libraries in build?
I have a directory structure like this:
app/ inc/ www/
inc/ contains code that is common to app and www. to create an image for app I do:
cd app docker build .
so the context for the build are the contents of
app/. of course, the code in
inc/ will be missing from the app and it breaks
googling I’ve read suggestions that I should:
docker build -f app/Dockerfile .
inc/ (good) but also includes everything else (bad) e.g. www
to solve the problem I would have to build a script that copies the contents of
app/, performs the build and the deletes
app/inc/. but that’s messy and, actually, I can’t do it because I want docker-compose to do my builds.
what is the recommended way to manage this?
One Solution collect form web for “How to include local libraries in build?”
but also includes everything else (bad) e.g. www
That is where a
.dockerignore file can come in handy: declare
www/ in it.
Before the docker CLI sends the context to the docker daemon, it looks for a file named
.dockerignorein the root directory of the context.
If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it.
This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon and potentially adding them to images using
Wrapping docker build or docker compose to generate the right
.dockerignore would be ideal for now.
Ultimately, each build should be able to specify its own
See issue 12886.
This feature was put on hold, pending other changes that are being researched/worked on; one of those is making the builder “smarter” when sending the build context; see #31829.