Generate a fully-functional Dockerfile from any codebase in just a few clicks! This project streamlines the entire containerization process by reading your project’s source files, analyzing them with code2prompt, and calling a Gemini LLM to produce a well-structured, minimal Dockerfile for your app.
-
Zero Docker Knowledge Required
Provide a codebase (as a ZIP), and instantly get a Dockerfile tailored to your project’s framework and dependencies. -
Automatic Language Detection
Leverages code2prompt to detect your code’s language, frameworks, and libraries. -
Powered by Gemini LLM
Integrates Google’s Gemini LLM for advanced natural-language instructions about how to structure your Dockerfile. -
Flexible Patterns
Specify include and exclude patterns to control which files are part of the container build. -
Optional Template Support
Pass a custom Handlebars/Jinja2 template for specialized Dockerfile layouts. -
Seamless UI
Built with Streamlit, ensuring an intuitive, web-based interface for Dockerfile generation.
- Python 3.8+
- Streamlit for the interactive web UI
- code2prompt for scanning codebases
- Gemini LLM API for intelligent Dockerfile generation
- [OpenAI python-dotenv, requests, etc.] for environment management and additional AI capabilities
┌──────────────┐ ┌─────────────────────┐
│ User Upload │ →→→ │ code2prompt │ →→→ Summarized code
│ ZIP File │ │(Analyze Codebase) │
└──────────────┘ └─────────────────────┘
↓
┌─────────────────────┐
│ Gemini LLM │
│(Generate Dockerfile)│
└─────────────────────┘
↓
┌─────────────────────┐
│ Streamlit UI │
│(Display Dockerfile) │
└─────────────────────┘
- User uploads a ZIP of the codebase.
- code2prompt enumerates & summarizes all source files.
- Gemini LLM gets the summarization + user instructions to generate a Dockerfile.
- Streamlit displays the final Dockerfile in a user-friendly interface.
-
Clone the Repository
git clone https://github.com/your-username/dockerfile-generator.git cd dockerfile-generator
-
Create & Activate a Virtual Environment
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install Dependencies
pip install -r requirements.txt
-
Set Environment Variables
Create a.env
file (or otherwise set these in your environment):GEMINI_API_KEY=<YOUR_GEMINI_API_KEY>
GEMINI_API_KEY
is used by the Gemini LLM API.
- Start the Streamlit App
streamlit run app.py
- Open in Your Browser
By default, Streamlit runs at http://localhost:8501. - Upload a ZIP
Click “Browse files” to upload your project’s source code as a ZIP. - (Optional) Enter Additional Instructions
E.g., “Use Python 3.9 as the base image and install pip packages fromrequirements.txt
.” - Generate Dockerfile
The tool runscode2prompt
→ calls Gemini LLM → returns your Dockerfile. - Download Dockerfile
Click the “Download Dockerfile” button to get it locally.
Key | Description | Default |
---|---|---|
GEMINI_API_KEY |
Your Gemini LLM API key. | (none) |
include_patterns |
Comma-separated patterns to include (e.g. *.py ) |
(none) |
exclude_patterns |
Comma-separated patterns to exclude (e.g. *.md ) |
(none) |
template_path |
Path to a custom Dockerfile template (Handlebars/Jinja2). | (none) |
Put these in .env
or set them as environment variables.
- ZIP Your Project
Suppose your Python Flask app is at~/MyFlaskApp/
.zip -r myapp.zip MyFlaskApp
- Launch
streamlit run app.py
- Upload the
myapp.zip
file. - Optionally specify includes like
*.py
or excludes like*.txt
. - Generate the Dockerfile, which might contain
FROM python:3.9
,COPY . .
,RUN pip install ...
, etc.
The CLI module allows you to generate Dockerfiles from a codebase using code2prompt
and the Gemini model. It supports both local directories and GitHub repository URLs as input.
-
Clone the repository:
git clone https://github.com/your-repo/Codebase-2-DockerFile.git cd Codebase-2-DockerFile
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the root directory and add your Gemini API key:GEMINI_API_KEY=your_gemini_api_key_here
The CLI tool can be used to generate Dockerfiles from a codebase. It supports the following arguments:
python cli.py <codebase_path> [options]
codebase_path
: Path to the codebase (local directory or GitHub URL).-i
or--include
: Include patterns (e.g.,*.py,*.js
).-e
or--exclude
: Exclude patterns (e.g.,*.txt,*.md
).-t
or--template
: Path to a customcode2prompt
template.-a
or--instructions
: Additional instructions for Dockerfile generation.-o
or--output
: Output file name (default:Dockerfile
).
python cli.py https://github.com/LikithMeruvu/Python-coding-Agent.git -a "Use Python 3.9" -o MyDockerfile
python cli.py ./my-codebase -i "*.py" -e "*.txt" -a "Use Python 3.8" -o MyDockerfile
python cli.py https://github.com/LikithMeruvu/Python-coding-Agent.git -t ./custom_template.txt -o MyDockerfile
-
Clone or Use Local Codebase:
- If a GitHub URL is provided, the repository is cloned to a temporary directory.
- If a local directory is provided, it is used directly.
-
Run
code2prompt
:- The
code2prompt
tool generates a prompt from the codebase based on the provided include/exclude patterns and template.
- The
-
Generate Dockerfile:
- The prompt is sent to the Gemini model, which generates the Dockerfile content.
-
Save Dockerfile:
- The generated Dockerfile is saved to the specified output file.
- If the codebase cannot be cloned or accessed, an error message is displayed.
- If
code2prompt
fails to generate a prompt, the process stops, and an error is shown. - If the Gemini model fails to generate a Dockerfile, an error is displayed.
This project is licensed under the MIT License.
Feel free to use, modify, and distribute it as you see fit.
Give us a Star!
If you find this project helpful, please consider giving it a star on GitHub. It helps others discover this project too!
Happy containerizing!