List of used files in the Docker context

Viewed 7532

Let's say I got a repository with multiple projects structured like this:

Root
 ├── bar
 │   ├── Dockerfile
 │   └── index.js
 ├── baz
 │   ├── Dockerfile
 │   └── index.js
 ├── foo
 │   ├── Dockerfile
 │   └── index.js
 └── shared
     └── utils.js
     └── shared.js

The Foo, Bar and Baz projects share some libraries in the shared folder. Currently, I'm sending the root folder as context to build these three Docker images to include the shared folder.

To increase build time and reduce deployment time of my Docker images, I need to get the minimum size of context sent to these images.

In order to do so, I plan on making a temporary folder for each images that will be used as context. Thing is, I need to know which shared files are used by each images.

In this example, its quite simple because there is few shared files and few projects. But in reality, there are hundreds of shared files and about 20 projects, and I don't want to check which shared files are used by which projects.

Here is an example of my Dockerfile:

FROM node:boron

RUN mkdir /app
WORKDIR /app

COPY package.json package.json
RUN yarn

COPY . .

RUN yarn release

CMD node release/server.js

And I build the Docker image with:

docker build -t foo:latest ..

Note the .. that point to the Root folder. This will result in all the shared files sent to the context, even those that are not needed.

Is there an easy way to know which files of the sent context to Docker are used by it and which are not?

5 Answers
Related