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:

  • centos6.6 in Dockerfile gives error
  • Docker build fails with Hash Sum Mismatch error [closed]
  • Not able to access shared data volume
  • Docker - cannot access container from Mac Host
  • Kubernetes Replication controller deletion
  • Connect to a VNC inside a docker which is on remote server
  • 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?

  • Change Docker for windows to use another VM besides MobylinuxVM
  • Docker swarm load balancing on AWS not working
  • Combine Dockerfiles on build
  • Windows 7 - Error: connect ENOENT //./pipe/docker_engine
  • Gitlab cross project dependency - python
  • Setting up Docker Postgres inside Python container
  • 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.