A Swift-based alternative to Docker Compose that translates docker-compose.yml files into container command executions. This tool provides a lightweight way to manage multi-container applications using the container CLI instead of Docker.
- Full docker-compose.yml parsing: Supports most Docker Compose file format features
- Environment variable resolution: Handles
.envfiles and variable substitution (${VAR:-default},${VAR:?error}) - Network management: Creates and manages custom networks
- Volume management: Creates named volumes and handles bind mounts
- Service orchestration: Builds images and runs containers with proper configuration
- Build support: Handles
buildcontexts with Dockerfile and build arguments - Comprehensive logging: Detailed output for debugging and monitoring
- Services: Image, build, environment, volumes, networks, ports, restart policies
- Networks: Custom networks with drivers and configuration
- Volumes: Named volumes and bind mounts
- Environment:
.envfiles, environment variables, variable substitution - Build: Build contexts, Dockerfiles, build arguments
- Container Configuration: User, hostname, working directory, privileged mode, read-only
- Configs: Parsed but not attached to containers (Swarm-specific feature)
- Secrets: Parsed but not attached to containers (Swarm-specific feature)
- Deploy: Parsed but orchestration features not implemented
- Port mappings: The
containertool doesn't support-pflag - Restart policies: Not supported by
container run - Healthchecks: Parsed but not implemented
- Dependencies:
depends_onis parsed but startup order not enforced - Volumns: Works well when mapping to a directory, but compose does not support mapping directly to a file presently
- Swift 5.0 or later
containerCLI tool installed and available in PATH- Yams Swift YAML library
# Clone the repository
git clone <repository-url>
cd container-compose
# Add Yams dependency to Package.swift
swift package add-dependency https://github.com/jpsim/Yams.git
# Build the executable
swift build -c release
# Copy to PATH (optional)
cp .build/release/container-compose /usr/local/bin/# Navigate to directory containing docker-compose.yml
cd /path/to/your/project
# Start services (equivalent to docker-compose up)
container-compose up
# Start services in detached mode
container-compose up -dyour-project/
├── docker-compose.yml
├── .env (optional)
├── Dockerfile (if using build)
└── other-files/
version: '3.8'
name: my-project
services:
web:
build: .
environment:
- NODE_ENV=production
- DATABASE_URL=${DATABASE_URL:-postgresql://localhost/myapp}
volumes:
- ./src:/app/src
- web-data:/app/data
networks:
- app-network
depends_on:
- db
db:
image: postgres:13
environment:
POSTGRES_DB: myapp
POSTGRES_PASSWORD: ${DB_PASSWORD:?Database password required}
volumes:
- db-data:/var/lib/postgresql/data
networks:
- app-network
volumes:
web-data:
db-data:
networks:
app-network:
driver: bridgeCreate a .env file in the same directory as your docker-compose.yml:
DATABASE_URL=postgresql://localhost/myapp_dev
DB_PASSWORD=supersecret
NODE_ENV=developmentcontainer-compose up [-d]Options:
-d, --detach: Run containers in the background (detached mode)
Currently supported subcommands:
up: Create and start containers
- Parse: Reads and validates
docker-compose.ymlusing Swift's Codable and Yams - Environment: Loads variables from
.envfiles and resolves substitutions - Networks: Creates custom networks defined in the compose file
- Volumes: Creates named volumes defined in the compose file
- Build: Builds images for services with build configurations
- Run: Executes
container runcommands for each service with appropriate flags
Supports Docker Compose variable substitution syntax:
${VARIABLE}- Simple substitution${VARIABLE:-default}- Use default if variable is unset${VARIABLE:?error message}- Exit with error if variable is unset
- Named volumes: Creates volumes using
container volume create - Bind mounts: Maps host directories to container paths
- Auto-creation: Creates missing host directories for bind mounts
- Custom networks: Creates networks with specified drivers and options
- External networks: References existing networks without creating them
- Default behavior: Services without explicit networks use default bridge network
- Context: Supports build contexts and custom Dockerfiles
- Arguments: Passes build arguments with variable resolution
- Tagging: Uses service image name or generates default tags
This tool is designed to work with the container CLI, which has some limitations compared to Docker:
- No port mapping: The
-pflag is not supported bycontainer run - No restart policies: Automatic restart is not available
- No healthchecks: Health monitoring is not implemented
- No dependency ordering: Services start independently
- Limited Swarm features: Configs and secrets are parsed but not used
Error: docker-compose.yml not found
# Ensure you're in the correct directory
ls -la docker-compose.ymlError: Missing required environment variable
# Check your .env file or export the variable
export REQUIRED_VAR=valueError: Container command not found
# Ensure container CLI is installed and in PATH
which containerBuild failures
# Check build context and Dockerfile paths
# Ensure all build dependencies are availableThe tool provides verbose output showing:
- Parsed configuration values
- Environment variable resolution
- Network and volume creation
- Exact
containercommands being executed
container-compose/
├── Sources/
│ └── main.swift # Main application logic
├── Package.swift # Swift package configuration
└── README.md # This file
- DockerCompose struct: Represents the complete compose file structure
- Service struct: Individual service configuration
- Environment resolution: Variable substitution logic
- Command execution: Interface to
containerCLI
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
MIT
- Built with Swift and the Yams YAML parsing library
- Inspired by Docker Compose's functionality
- Designed for use with Apples Container runtime that provide a Docker-(Semi)compatible CLI