You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
constcomposerize=require('composerize');constdockerRunCommand='docker run -d -p 8080:80 --name my-web-app nginx:latest';// Convert the Docker run command to a Docker Compose configurationconstcomposeConfig=composerize(dockerRunCommand);console.log(composeConfig);
You can also merge docker run command(s) with an existing Docker Compose file content :
constcomposerize=require('composerize');constdockerRunCommand='docker run -d -p 8080:80 --name my-web-app nginx:latest';// An existing Docker Compose configuration as a stringconstexistingComposeConfig=`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 composeconstcomposeConfig=composerize(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'
constcomposerize=require('composerize');constdockerRunCommand='docker run -d -p 8080:80 --name my-web-app nginx:latest';// Convert the Docker run command to a Docker Compose configuration for 2.xconstcomposeConfig=composerize(dockerRunCommand,null,'v2x');console.log(composeConfig);
You can also choose indentation level by specifying a fourth parameter indent on convertDockerRunToCompose :
'v2x'
'v3x'
'latest'
constcomposerize=require('composerize');constdockerRunCommand='docker run -d -p 8080:80 --name my-web-app nginx:latest';// Convert the Docker run command to a Docker Compose configuration for 2.xconstcomposeConfig=composerize(dockerRunCommand,null,'latest',2);console.log(composeConfig);