A CLI tool to automatically minimize Dockerfiles by analyzing the dependencies of containerized applications.
- Static Analysis: Identifies linked libraries using
ldd. - Dynamic Analysis: Uses
straceto monitorexecveandopencalls to determine runtime dependencies. - Binary Search: If dynamic analysis fails, it tries to minimize the container using a binary search approach.
The tool has been tested on various applications, yielding the following results:
To install dockerminimizer locally, you can use the following command:
git clone https://github.com/ReGeLePuMa/dockerminimizer.git
cd dockerminimizer
./install.shAlternatively, you can use the following container image:
docker run \
--rm \
--privileged \
-v /root/.dockerminimizer:/root/.dockerminimizer \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(pwd):/app \
regelepuma/dockerminimizerdockerminimizer --help
A tool to minimize Dockerfiles by determining the dependencies of the containerized application
Usage:
dockerminimizer [flags]
Flags:
--binary_search Continue with binary search if dynamic analysis fails (default true)
--debug Enable debug mode
-f, --file string Path to the Dockerfile (default "./Dockerfile")
-h, --help help for dockerminimizer
-i, --image string Name of the Docker image
--max_limit int Number of binary search steps (default 10)
--model string AI model to use for analysis (e.g., 'gemini-3.5-flash')
--provider string AI provider to use for analysis (e.g., 'google')
--strace_path string Path to the statically linked strace binary (default "/usr/local/bin/strace")
--timeout int How long the container should run before being declared healthy (default 30)
--token string API token for the AI serviceFor this NodeJS app, with the following Dockerfile:
FROM node:20.9.0
WORKDIR /app
COPY app.js /app/app.js
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
RUN npm install
EXPOSE 3000
CMD ["node", "app.js"]Running the command:
dockerminimizer -f Dockerfilewill produce a new Dockerfile in the current directory named Dockerfile.minimal:
FROM node:20.9.0
WORKDIR /app
COPY app.js /app/app.js
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
RUN npm install
EXPOSE 3000
CMD ["node", "app.js"]
FROM scratch
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
WORKDIR /app
EXPOSE 3000/tcp
CMD ["node", "app.js"]
COPY --from=builder ["/app/node_modules/morgan/node_modules/debug/package.json", "/app/node_modules/morgan/node_modules/debug/"]
COPY --from=builder ["/app/node_modules/body-parser/package.json", "/app/node_modules/body-parser/index.js", "/app/node_modules/body-parser/"]
COPY --from=builder ["/app/node_modules/ipaddr.js/lib/ipaddr.js", "/app/node_modules/ipaddr.js/lib/"]
COPY --from=builder ["/app/node_modules/qs/lib/index.js", "/app/node_modules/qs/lib/stringify.js", "/app/node_modules/qs/lib/utils.js", "/app/node_modules/qs/lib/formats.js", "/app/node_modules/qs/lib/parse.js", "/app/node_modules/qs/lib/"]
.
.
.
