How to include local libraries in build?

I have a directory structure like this:

app/
inc/
www/

where inc/ contains code that is common to app and www. to create an image for app I do:

  • Deploy and debug a remote Linux Docker container using Visual Studio Tools for Docker
  • Docker container with build output and no source
  • Docker image size not matching the announced size on https://github.com/docker-library/repo-info
  • Docker logging to container
  • Docker how to start container with defined nameservers in /etc/resolv.conf
  • Cannot detect Linux distribution or it’s unsupported
  • 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 .
    

    which includes 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 inc/ into 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?

  • SkyDNS does not work with Kubernetes 1.1.2
  • Unexpected behaviour from awk in docker-machine
  • Dynamically set JAVA_HOME of docker container
  • When does Docker write to iptables?
  • Enable external network access from my docker swarm
  • “kubectl exec” results in “error: unable to upgrade connection: Unauthorized”
  • 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 .dockerignore in 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 ADD or COPY.

    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 dockerignore file.
    See issue 12886.
    However:

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.