1.6.10 • Published 1 month ago

composerize v1.6.10

Weekly downloads
25
License
MIT
Repository
-
Last release
1 month ago

composerize

Build Status npm Follow @mark_larah ShareVB on GitHub

http://composerize.com - Turns docker run commands into docker-compose.yml files and even merge with existing docker-compose.yml!

Looking for the reverse : http://decomposerize.com / Decomposerize

Want to convert from Docker compose file formats : http://composeverter.com / Composeverter

Demo

CLI

composerize can be run in the cli.

npm install composerize -g to install, and run as such:

$ composerize docker run -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro --restart always --log-opt max-size=1g nginx

How to use with node.js

Make sure to install the composerize package in your project by running:

npm install composerize

With the following code, you can easily integrate Composerize into your Node.js project and generate Docker Compose configurations from Docker run commands.

const { convertDockerRunToCompose } = require('composerize');

const dockerRunCommand = 'docker run -d -p 8080:80 --name my-web-app nginx:latest';

// Convert the Docker run command to a Docker Compose configuration
const composeConfig = convertDockerRunToCompose(dockerRunCommand);

console.log(composeConfig);

You can also merge docker run command(s) with an existing Docker Compose file content :

const { convertDockerRunToCompose } = require('composerize');

const dockerRunCommand = 'docker run -d -p 8080:80 --name my-web-app nginx:latest';

// An existing Docker Compose configuration as a string
const existingComposeConfig = `
version: '3'
services:
  existing-service:
    image: my-existing-image:latest
    ports:
      - '8000:80'
`;

// Convert the Docker run command to a Docker Compose configuration and merge with provided docker compose
const composeConfig = convertDockerRunToCompose(dockerRunCommand, existingComposeConfig);

console.log(composeConfig);

You can also choose which version of Docker compose V2, you target : 2.x, 3.x or Common Specification by specifying a third parameter composeVersion on convertDockerRunToCompose :

  • 'v2x'
  • 'v3x'
  • 'latest'
const { convertDockerRunToCompose } = require('composerize');

const dockerRunCommand = 'docker run -d -p 8080:80 --name my-web-app nginx:latest';

// Convert the Docker run command to a Docker Compose configuration for 2.x
const composeConfig = convertDockerRunToCompose(dockerRunCommand, null, 'v2x');

console.log(composeConfig);

You can also choose indentation level by specifying a fourth parameter indent on convertDockerRunToCompose :

  • 'v2x'
  • 'v3x'
  • 'latest'
const { convertDockerRunToCompose } = require('composerize');

const dockerRunCommand = 'docker run -d -p 8080:80 --name my-web-app nginx:latest';

// Convert the Docker run command to a Docker Compose configuration for 2.x
const composeConfig = convertDockerRunToCompose(dockerRunCommand, null, 'latest', 2);

console.log(composeConfig);

Contributing

  • Clone a fork of the repo and install the project dependencies by running yarn
  • Make your changes, and build the project by running make build
  • Test your changes with make test

yarn version

Needs yarn@1.19.1. See https://github.com/yarnpkg/yarn/issues/7734.

Maintainers

1.6.10

1 month ago

1.6.8

2 months ago

1.6.7

2 months ago

1.6.6

4 months ago

1.6.4

5 months ago

1.6.3

5 months ago

1.6.5

5 months ago

1.6.2

5 months ago

1.6.1

5 months ago

1.6.0

6 months ago

1.5.0

6 months ago

1.4.1

7 months ago

1.4.0

7 months ago

1.3.1

8 months ago

1.3.0

8 months ago

1.2.0

1 year ago

1.1.0

2 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

5 years ago

1.0.1

7 years ago

1.0.0-alpha.10

7 years ago

1.0.0-alpha.9

7 years ago

1.0.0-alpha.8

7 years ago

1.0.0-alpha.7

7 years ago

1.0.0-alpha.6

7 years ago

1.0.0-alpha.5

7 years ago

1.0.0-alpha.4

7 years ago

1.0.0-alpha.3

7 years ago

1.0.0-alpha.2

7 years ago

1.0.0-alpha.1

7 years ago