(self.webpackChunkdocker_compose=self.webpackChunkdocker_compose||[]).push([[509],{422:(n,s,e)=>{"use strict";e.r(s),e.d(s,{data:()=>o});const o={key:"v-8daa1a0e",path:"/",title:"Manage Docker-Compose via Node.js",lang:"en-US",frontmatter:{title:"Manage Docker-Compose via Node.js",lang:"en-US",home:!1},excerpt:"",headers:[{level:2,title:"Installation",slug:"installation",children:[]},{level:2,title:"Usage",slug:"usage",children:[{level:3,title:"Example",slug:"example",children:[]},{level:3,title:"Options",slug:"options",children:[]}]},{level:2,title:"Running the tests",slug:"running-the-tests",children:[]},{level:2,title:"Want to help?",slug:"want-to-help",children:[{level:3,title:"Discussions",slug:"discussions",children:[]}]},{level:2,title:"License",slug:"license",children:[]}],filePathRelative:"README.md",git:{updatedTime:1638169024e3,contributors:[]}}},467:(n,s,e)=>{"use strict";e.r(s),e.d(s,{default:()=>j});var o=e(252);const a=(0,o.Wm)("h1",{id:"manage-docker-compose-via-node-js"},[(0,o.Wm)("a",{class:"header-anchor",href:"#manage-docker-compose-via-node-js"},"#"),(0,o.Uk)(" Manage Docker-Compose via Node.js")],-1),t=(0,o.Wm)("code",null,"docker-compose",-1),c=(0,o.Uk)(" is a small library that allows you to run "),i={href:"https://docs.docker.com/compose/",target:"_blank",rel:"noopener noreferrer"},p=(0,o.Uk)("docker-compose"),l=(0,o.Uk)(" (which is still required) via Node.js. This is useful to bootstrap test environments."),r=(0,o.uE)('

# Installation

npm install --save-dev docker-compose\n
1

# Usage

docker-compose current supports these commands:

All commands return a Promise({object}) with stdout and stderr strings and an exit code:

{\n  out: 'stdout contents',\n  err: 'stderr contents',\n  exitCode: 0, // !== 0 in case of an error\n}\n
1
2
3
4
5

Although the return type is a Promise, it is still possible to get the process progres before the Promise resolves, by passing a callback function to the optional callback parameter.

# Example

To start service containers based on the docker-compose.yml file in your current directory, just call compose.up like this:

compose.upAll({ cwd: path.join(__dirname), log: true })\n  .then(\n    () => { console.log('done')},\n    err => { console.log('something went wrong:', err.message)}\n  );\n
1
2
3
4
5

To get process progres

compose.upAll({\n   cwd: path.join(__dirname),\n   callback: (chunk: Buffer) => {\n     console.log('job in progres: ', chunk.ToString())\n      }\n   })\n  .then(\n    () => { console.log('job done')},\n    err => { console.log('something went wrong:', err.message)}\n  );\n
1
2
3
4
5
6
7
8
9
10

To execute command inside a running container

compose.exec('node', 'npm install', { cwd: path.join(__dirname) })\n
1

# Options

docker-compose accepts these params:

# Running the tests

While docker-compose runs on Node.js 6+, running the tests requires you to use Node.js 8 as they make use of async/await.

yarn test\n
1

# Want to help?

This project is just getting off the ground and could use some help with cleaning things up and refactoring.

If you want to contribute - we'd love it! Just open an issue to work against so you get full credit for your fork. You can open the issue first so we can discuss and you can work your fork as we go along.

If you see a bug, please be so kind as to show how it's failing, and we'll do our best to get it fixed quickly.

',25),u=(0,o.Uk)("Before sending a PR, please "),d={href:"https://github.com/PDMLab/docker-compose/issues/new",target:"_blank",rel:"noopener noreferrer"},m=(0,o.Uk)("create an issue"),k=(0,o.Uk)(" to introduce your idea and have a reference for your PR."),g=(0,o.Uk)("We're using "),h={href:"https://www.conventionalcommits.org",target:"_blank",rel:"noopener noreferrer"},f=(0,o.Uk)("conventional commits"),b=(0,o.Uk)(", so please use it for your commits as well."),v=(0,o.Wm)("p",null,[(0,o.Uk)("Also please add tests and make sure to run "),(0,o.Wm)("code",null,"yarn lint"),(0,o.Uk)(".")],-1),w=(0,o.Wm)("h3",{id:"discussions"},[(0,o.Wm)("a",{class:"header-anchor",href:"#discussions"},"#"),(0,o.Uk)(" Discussions")],-1),y=(0,o.Uk)("If you want to discuss an "),R=(0,o.Wm)("code",null,"docker-compose",-1),T=(0,o.Uk)(" issue or PR in more detail, feel free to "),O={href:"https://github.com/PDMLab/docker-compose/discussions",target:"_blank",rel:"noopener noreferrer"},A=(0,o.Uk)("start a discussion"),E=(0,o.Uk)("."),I=(0,o.Wm)("h2",{id:"license"},[(0,o.Wm)("a",{class:"header-anchor",href:"#license"},"#"),(0,o.Uk)(" License")],-1),W=(0,o.Wm)("p",null,"MIT License",-1),S=(0,o.Wm)("p",null,"Copyright (c) 2017 - 2021 PDMLab",-1),N=(0,o.Wm)("p",null,'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:',-1),U=(0,o.Wm)("p",null,"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.",-1),q=(0,o.Wm)("p",null,'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.',-1),j={render:function(n,s){const e=(0,o.up)("OutboundLink");return(0,o.wg)(),(0,o.j4)(o.HY,null,[a,(0,o.Wm)("p",null,[t,c,(0,o.Wm)("a",i,[p,(0,o.Wm)(e)]),l]),r,(0,o.Wm)("p",null,[u,(0,o.Wm)("a",d,[m,(0,o.Wm)(e)]),k]),(0,o.Wm)("p",null,[g,(0,o.Wm)("a",h,[f,(0,o.Wm)(e)]),b]),v,w,(0,o.Wm)("p",null,[y,R,T,(0,o.Wm)("a",O,[A,(0,o.Wm)(e)]),E]),I,W,S,N,U,q],64)}}}}]);