composerize-np
Rust version of composerize - a powerful tool for:
- 🐳 Converting
docker runcommands todocker-compose.yamlor JSON files - 🔄 Converting between YAML ↔ JSON formats
- ⚡ Fast operation, single executable, no dependencies
Quick Start
# Simplest way - just pass the docker command
# Save to YAML file (docker-compose.yml)
# ⚠️ For long/complex commands - use a file!
# This solves escaping and length limitation issues
# Save to JSON file (docker-compose.json)
# Convert YAML to JSON
⚠️ IMPORTANT for PowerShell: If the command contains
||,&&,|or other special characters, use double double quotes""around the problematic value:# ❌ DOESN'T WORK in PowerShell (fails on ||) composerize-np "docker run --health-cmd='curl || exit 1' nginx" # ✅ WORKS: Use double double quotes "" composerize-np "docker run --health-cmd=""curl || exit 1"" nginx" # ✅ OR use --from-file (RECOMMENDED for very long commands) # 1. Save command to command.txt file # 2. Run: composerize-np --from-file command.txt -o
Installation
As a CLI tool
# Install from crates.io (after publication)
# Or build from source
The executable will be in target/release/composerize-np (or composerize-np.exe on Windows).
As a library
Add to your Cargo.toml:
[]
= "0.1"
Quick example:
use composerize;
See EXAMPLES.md for more examples and API documentation.
Usage
1. Converting docker run to compose
There are two ways to use it:
Option A: Simple way (direct command)
Fastest and most convenient for manual use
Just pass the docker command directly:
# YAML format (default)
# JSON format (output to console)
# Save YAML to file (docker-compose.yml by default)
# Save YAML to custom file
# Save JSON to file (docker-compose.json by default)
# Save JSON to custom file
# With formatting parameters
When to use:
- ✅ Quick conversion in terminal
- ✅ Compatibility with original composerize version
- ✅ Simple one-line commands
Option B: With run subcommand
Recommended for scripts and automation
Use explicit run subcommand:
# YAML format
# JSON format
# With parameters
When to use:
- ✅ In scripts and CI/CD
- ✅ When explicit command is needed for readability
- ✅ When using other subcommands (yaml-to-json, json-to-yaml)
Both options work identically! Choose whichever is more convenient for you.
| Criteria | Direct command | With run |
|---|---|---|
| Command length | Shorter | Longer |
| Readability in scripts | Medium | High |
| Compatibility with original | ✅ Yes | ❌ No |
| Intent clarity | Medium | High |
| Recommended for | Manual use | Scripts, CI/CD |
2. Converting YAML to JSON
# Output to console
# Save to file
# Without pretty-print
3. Converting JSON to YAML
# Output to console
# Save to file
4. Automatic conversion
The convert command automatically determines format by file extension:
# YAML → JSON
# JSON → YAML
Formatting parameters
# -f, --format: Docker Compose version (latest, v3x, v2x)
# -i, --indent: Number of spaces for indentation (default 2)
# Combination of parameters
Help
# General help
# Command help
Examples
Simple Nginx web server
# Option 1: Direct command (shorter)
# Option 2: With subcommand (more explicit)
Result:
services:
nginx:
image: nginx
ports:
- 80:80
MySQL with environment variables (JSON)
Result:
Converting existing compose file
# Have docker-compose.yml, need JSON
# Edit JSON...
# Convert back to YAML
Supported Flags
Full support for all major Docker flags:
Network and ports
-p, --publish- ports--expose- expose ports--network, --net- network--network-alias- network aliases--ip- IPv4 address--ip6- IPv6 address--link- container links--add-host- additional hosts--dns- DNS servers--dns-search- DNS search domains--dns-opt- DNS options--mac-address- MAC address
Volumes and filesystem
-v, --volume- volumes--mount- mount--volumes-from- volumes from other containers--tmpfs- tmpfs mount--read-only- read-only--workdir, -w- working directory
Environment and configuration
-e, --env- environment variables--env-file- environment file--name- container name--hostname, -h- hostname--domainname- domain name--user, -u- user--label, -l- labels--entrypoint- entrypoint--platform- platform
Resources
--memory, -m- memory limit--memory-swap- swap limit--memory-reservation- memory reservation--memory-swappiness- swappiness--cpus- CPU count--cpu-shares, -c- CPU shares--cpu-period- CPU period--cpu-quota- CPU quota--cpu-rt-period- CPU RT period--cpu-rt-runtime- CPU RT runtime--pids-limit- process limit--ulimit- ulimits--device- devices--gpus- GPU
Security and privileges
--privileged- privileged mode--cap-add- add capabilities--cap-drop- drop capabilities--security-opt- security options--userns- user namespace--group-add- additional groups
Behavior and policies
--restart- restart policy-d, --detach- run in background-t, --tty- allocate pseudo-TTY-i, --interactive- interactive mode--init- use init--rm- remove after stop--pull- pull policy--stop-signal- stop signal--stop-timeout- stop timeout
Logging
--log-driver- logging driver--log-opt- logging options
Healthcheck
--health-cmd- health check command--health-interval- check interval--health-retries- retry count--health-timeout- check timeout--health-start-period- start period--no-healthcheck- disable healthcheck
Other
--cgroup-parent- parent cgroup--cgroupns- cgroup namespace--ipc- IPC mode--pid- PID mode--uts- UTS namespace--isolation- isolation--runtime- runtime--shm-size- /dev/shm size--sysctl- sysctl parameters--storage-opt- storage options--blkio-weight- Block IO weight--device-read-bps- device read limit--device-write-bps- device write limit--device-read-iops- read IOPS limit--device-write-iops- write IOPS limit--oom-kill-disable- disable OOM killer--oom-score-adj- OOM score adjustment
Automatic Networks and Volumes Sections
composerize-np automatically creates networks: and volumes: sections at the root of the compose file for used resources:
Networks
- Automatically adds
networks:section for custom networks - Marks them as
external: true(assumes network is created beforehand) - Ignores standard networks:
default,bridge,host,none
Result:
services:
nginx:
networks:
ml-net:
image: nginx
networks:
ml-net:
external: true
Volumes
- Automatically adds
volumes:section for named volumes - Does NOT add bind mounts (paths starting with
/,.,~) - Named volumes are declared as
null(created by Docker automatically)
Result:
services:
nginx:
volumes:
- data:/data
- cache:/cache
- /host:/host
image: nginx
volumes:
data: null
cache: null
Full example with GPU, networks and volumes
Result - fully valid compose file:
services:
tensorflow:
container_name: ml-gpu
networks:
ml-net:
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities:
- gpu
volumes:
- ml-models:/models
- ml-cache:/cache
tmpfs:
- /tmp:rw,size=256m
healthcheck:
test:
- CMD-SHELL
- curl -f http://localhost:5000/health || exit 1
interval: 20s
ports:
- 5000:5000
image: tensorflow/tensorflow:latest-gpu
networks:
ml-net:
external: true
volumes:
ml-models: null
ml-cache: null
This file fully complies with Docker Compose specification and is ready to use!
Testing
The project has full test coverage:
- 41 unit tests (including networks/volumes tests)
- 18 integration tests
# Run all tests
# Run with output
See TESTING.md for detailed information.
Development
# Clone repository
# Build
# Run tests
# Build release version
# Install locally
Documentation
For CLI Users
- 📋 CHEATSHEET.md - Quick cheat sheet with command examples (including PowerShell tips)
- ❓ FAQ.md - Frequently Asked Questions
For Library Users
- 📚 LIBRARY_USAGE.md - Complete guide for using as a library
- 💡 EXAMPLES.md - Detailed examples with explanations
- 🔧 examples/ - Runnable code examples (
cargo run --example basic_usage) - 📖 API Documentation - Full API reference (after publication)
FAQ
Have questions? See FAQ.md with answers to common questions:
- What's the difference between direct command and
run? - How to choose between YAML and JSON?
- How to convert between formats?
- Which flags are supported?
- And much more!
License
MIT