A CLI tool to automate SQL database container management for developers using Docker.
Project description
Dbdev
Dbdev is a powerful CLI tool that helps developers easily create, list, and manage SQL database containers using Docker. It supports multiple database engines (MySQL, PostgreSQL, MariaDB, and more), generates secure credentials, and is built for easy local development. The tool can be used via PyPI, via Docker, or with Docker Compose.
🔗 Library link
🚀 Features
- Easy CLI: Create, list, and remove database containers from the command line
- Multi-DB Support: MySQL, PostgreSQL, MariaDB (and easily extensible)
- Secure Credentials: Generates strong, random passwords
- Configurable: Use environment variables and
.envfiles - Logging & Error Handling: Robust, production-oriented output
- Extensible: Modular Python code ready for new features
- Docker-Ready: Can be used as a local CLI, via PyPI, also via Docker, or via Docker Compose
📦 Requirements
-
Docker: Must be installed and running on your machine
-
Python 3.8+ (for using the library/CLI via PyPI/pip)
🔧 How can I use?
Note:
- The CLI uses your local Docker daemon to manage database containers.
- Docker must be installed and running on your machine.
- The library does NOT install or manage Docker itself.
Run via PyPI (Easiest way)
-
Ensure Docker is installed and running on your machine.
-
Install the CLI globally or in a virtual environment:
pip install dbdev
-
Use the CLI:
dbdev --help dbdev create --image mysql --db testdb --user myuser dbdev list dbdev remove --id <container_id>
Tip:
If you encounter permission errors, you may need to run Docker with sudo (Linux) or ensure your user is in the docker group.
Run Locally (Development Mode)
-
Clone the repository:
git clone https://github.com/leticiamantovani/dbdev.git cd dbdev
-
(Recommended) Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install the package in editable mode (and pytest for testing):
pip install -e . pip install pytest
-
Ensure Docker is installed and running on your machine.
-
Use the CLI:
dbdev --help dbdev create --image mysql --db testdb --user myuser dbdev list dbdev remove --id <container_id> OR <db_name>
Run via Docker
If you prefer not to install Python or dependencies, you can use the CLI directly from a Docker container.
Build the Docker image:
docker build -t dbdev:v1 .
Important:
-
The volume flag
-v /var/run/docker.sock:/var/run/docker.sockis required to let the CLI inside the container access your host's Docker service. Without it, you will get connection errors like:DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
Run a command (example: list containers):
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
dbdev:v1 list
Run via Docker Compose
How to use:
-
Place the
docker-compose.ymlfile in your project root. -
Build and start the service:
docker-compose up --build
This shows the CLI help and, if set up with a custom entrypoint, drops you into a shell for debugging.
-
To use the CLI for specific commands (recommended):
docker-compose run --rm dbdev list docker-compose run --rm dbdev create --image mysql --db testdb --user myuser
⚡ Commands
Show help
dbdev --help
# or
python -m dbdev.cli --help
Create a new database container
dbdev create --image mysql --db mydb --user devuser --password mypass --root-password rootpass
--image: Database image (mysql, postgres, mariadb) [DEFAULT: mysql]--db: Name of the database to create [REQUIRED]--user: Database user [OPTIONAL, random if not provided]--password: User's password [OPTIONAL, random if not provided]--root-password: Root/admin password [OPTIONAL, random if not provided]
List all managed containers
dbdev list
Get details of a specific container
dbdev info <db_name>
db_name: Name of the database to create [REQUIRED]
Remove a database container
dbdev remove <container_id>
# or
dbdev remove <db_name>
container_id: ID of the container to remove [REQUIRED]db_name: Name of the database to create [REQUIRED]
⚙️ Configuration
You can use a .env file to set default values (automatically loaded if present):
DEFAULT_DB_IMAGE=mysql
DEFAULT_DB_PORT=3306
🐳 Supported Database Images
- MySQL (default)
- PostgreSQL
- MariaDB
Want support for another image? Open a pull request or submit a feature request!
🛠️ Development & Contribution
Contributions are welcome! To set up for local development:
git clone https://github.com/leticiamantovani/dbdev.git
cd dbdev
pip install -e .
pip install pytest
To run the tests:
pytest tests/
To add a new database image:
- Edit
src/dbdev/docker_manager.py, and add the image config inDB_IMAGES.
Open an issue or pull request with your improvements or bug reports.
🚨 Troubleshooting
-
Docker not installed/running: Make sure Docker is installed and running on your machine before using the CLI.
-
Permission denied on docker.sock: On Linux, you might need to add your user to the
dockergroup or usesudo. -
Docker socket not available in the container:
- Always run with
-v /var/run/docker.sock:/var/run/docker.sockto allow the CLI inside the container to control your host's Docker daemon.
- Always run with
-
PyPI install notes:
- The library only manages Docker containers using your local Docker service. It will not install Docker for you. Make sure Docker is running on your machine before using any CLI commands.
📝 License
MIT License. See LICENSE for details.
⭐ Credits
Created by Leticia Mantovani. Contributions, feedback, and issues are very welcome!
If you use and like this project, please give it a ⭐ on GitHub!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbdev-0.1.1.tar.gz.
File metadata
- Download URL: dbdev-0.1.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60359eb4450c4c40427a3087a5e81a87bd61f16a67e6014ee285ff56b5b7cc03
|
|
| MD5 |
371b84ce01703e2882a63c7365d9f779
|
|
| BLAKE2b-256 |
f7e040d65202f37f8c9ccdddad4fe1dea31f9273fe7cb1f540a082cab70e4f52
|
File details
Details for the file dbdev-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dbdev-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9268943411db05785700e57844084a630a3a53aa05a186872999ff5fab5d36a4
|
|
| MD5 |
d25f4639e2d62d91a4f9669693e027ff
|
|
| BLAKE2b-256 |
e61dd0a827cfe738458bb4822e6247cb0857097add2b60467847642b00fb2d06
|