This project is vibe code, be careful when using it!
A powerful Go tool that extracts Docker container configurations and creates development containers with enhanced debugging capabilities. This tool inspects running containers, parses their configurations, and generates development-ready clones with customizable features.
- Container Configuration Extraction: Automatically extracts complete container configurations using
docker inspect - Development Container Creation: Creates dev-ready containers based on production configurations
- Clean Architecture: Separates parsing, generation, and execution logic into reusable packages
- Debugger Support: Automatically installs and configures Delve debugger for Go applications
- Custom Volume Mounting: Supports dev-swap directories for development workflows
- Comprehensive Parsing: Handles all Docker configuration elements:
- Environment variables
- Volume mounts (bind and volume types, with ro/rw support)
- Port mappings
- Networks
- Working directories
- Labels
- Devices
- Extra hosts
- Restart policies
- EntryPoints and Commands
- Go 1.25 or higher
- Docker installed and running
- Access to Docker daemon
git clone https://github.com/yourusername/docker-config-extractor.git
cd docker-config-extractor
go build -o docker-config-extractorgo install github.com/yourusername/docker-config-extractor@latestExtract configuration from a container and create a dev container:
./docker-config-extractor <container-name> [dev-container-name] [dev-swap-dir]Simple clone:
./docker-config-extractor myapp
# Creates: myapp-devCustom dev container name:
./docker-config-extractor myapp myapp-developmentWith dev-swap directory:
./docker-config-extractor myapp myapp-dev /path/to/dev-workspace
# Mounts /path/to/dev-workspace as /dev-swap in containerdocker-config-extractor/
βββ main.go # Manager and CLI entry point
βββ go.mod # Go module definition
βββ pkg/
βββ containerconfig/
βββ spec.go # ContainerSpec data structures
βββ parser.go # JSON parsing logic
βββ generator.go # Docker run command generation
Defines the container configuration structure:
type ContainerSpec struct {
Name string
Image string
Env []string
Volumes []string
Ports []string
Networks []string
Command []string
WorkingDir string
Labels map[string]string
EntryPoint []string
Devices []string
ExtraHosts []string
Restart string
}Parses docker inspect JSON output into ContainerSpec:
spec, err := containerconfig.ParseInspectJSON(jsonData)Generates docker run commands from ContainerSpec:
runCmd := containerconfig.GenerateRunCommand(spec, opts)Orchestrates container operations with clean, single-responsibility methods:
GetContainerConfig()- Retrieves container configurationCreateDevContainer()- Creates development containerStopDevContainer()- Stops containerRemoveDevContainer()- Removes containerCheckDevContainerExists()- Checks container existence
You can use the containerconfig package in your own Go projects:
package main
import (
"fmt"
"github.com/yourusername/docker-config-extractor/pkg/containerconfig"
)
func main() {
// Parse container configuration
spec, err := containerconfig.ParseInspectJSON(jsonData)
if err != nil {
panic(err)
}
// Generate docker run command
opts := &containerconfig.RunOptions{
Name: "my-dev-container",
}
runCmd := containerconfig.GenerateRunCommand(spec, opts)
fmt.Println(runCmd)
}When creating a dev container, the tool automatically:
- Checks if Go is installed in the container
- Installs Delve debugger (
dlv) - Exposes port 2345 for remote debugging
- Verifies successful installation
# After container creation, you can attach the debugger:
docker exec -it myapp-dev dlv attach <pid>The tool supports injecting custom initialization scripts into the container after creation. This is useful for:
- Installing additional development tools
- Setting up environment configurations
- Running initialization scripts
# Check if container exists
# If exists, prompts for recreation
# Stop and remove existing container
# Create new dev container with updated configurationgo test ./...go build -vThis project follows clean architecture principles:
- Separation of Concerns: Parsing, generation, and execution are separate
- No Shell Command Chaining: Avoids
&&operators; uses separatedocker execcalls - Single Responsibility: Each method does one thing well
- Comprehensive Error Handling: All errors include context
- Extensive Logging: Clear visibility into operations
- Go 1.25+
- Docker Engine (tested with Docker 20.10+)
- Permissions: User must have Docker access
Contributions are welcome! Please feel free to submit a Pull Request.
- Follow Go conventions and best practices
- Add tests for new features
- Update documentation for API changes
- Ensure
go buildpasses before submitting
This project is licensed under the MIT License - see the LICENSE file for details.