expanse-docker-lib
v1.0.2
Published
A TypeScript library for working with Docker Compose configurations
Downloads
412
Maintainers
Readme
expanse-docker-lib
A TypeScript library for working with Docker Compose configurations, providing strong typing and easy manipulation of Docker Compose data structures.
This library powers expanse.dev and is a fork of the original compose-craft-lib.
Overview
expanse-docker-lib is a powerful TypeScript library designed to simplify working with Docker Compose configurations. It offers:
- Strong TypeScript typing for Docker Compose structures
- Easy creation and manipulation of compose configurations
- Translation between different representation formats
- Intuitive, object-oriented approach to defining services and configurations
Features
- Type-safe Docker Compose configuration management
- Support for creating and modifying services, images, and port mappings
- Translator design pattern for flexible configuration handling
- Comprehensive type definitions
Installation
Install the library using npm:
npm install expanse-docker-libOr using yarn:
yarn add expanse-docker-libOr using pnpm:
pnpm add expanse-docker-libUsage Examples
Basic Composition Creation
import { Compose, Service, Image, PortMapping, Translator } from "expanse-docker-lib"
import { stringify } from "yaml";
// Create a new Compose configuration
const compose = new Compose({name: "demo"});
// Define a web service
const webService = new Service({
name: "web",
image: new Image({ name: "nginx" }),
ports: [new PortMapping({ hostPort: 80, containerPort: 80 })],
});
// Add the service to the composition
compose.addService(webService);
// Translate to a dictionary and convert to YAML
const translator = new Translator(compose);
const yamlConfig = stringify(translator.toDict());API Documentation
For detailed API documentation, please visit the project GitHub repository.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the Apache-2.0 License. See LICENSE for more information.
Original library by Lucas Sovre.
Contact
Project Link: https://github.com/expanse-dev/docker-compose-lib
