Files
compose/example/basic_example.py
Joakim Hellsén 63160d682f Add initial implementation of Docker Compose manager and example usage
- Introduced DockerComposeManager class for programmatically creating and managing Docker Compose YAML files.
- Added example script demonstrating usage of DockerComposeManager.
- Created tests for service creation, modification, and removal.
- Included project metadata in pyproject.toml and added linting instructions in copilot-instructions.md.
2025-06-18 03:45:48 +02:00

37 lines
993 B
Python

"""Example usage of DockerComposeManager to generate a docker-compose.yaml file."""
from compose import DockerComposeManager
if __name__ == "__main__":
# Path to the compose file to generate
compose_path = "docker-compose.yaml"
# Create a DockerComposeManager instance
manager = DockerComposeManager(compose_path)
# Add a simple web service
manager.create_service(
name="web",
image="nginx:alpine",
ports=["8080:80"],
environment={"NGINX_HOST": "localhost"},
)
# Add a database service
manager.create_service(
name="db",
image="postgres:15-alpine",
environment={
"POSTGRES_USER": "user",
"POSTGRES_PASSWORD": "password",
"POSTGRES_DB": "exampledb",
},
ports=["5432:5432"],
volumes=["db_data:/var/lib/postgresql/data"],
)
# Save the compose file
manager.save()
print(f"docker-compose.yaml generated at {compose_path}")