An open API service indexing awesome lists of open source software.

https://github.com/jondotsoy/docker_child_process

Simple docker agent to NodeJS to run scripts in a container.
https://github.com/jondotsoy/docker_child_process

child-process docker

Last synced: about 2 months ago
JSON representation

Simple docker agent to NodeJS to run scripts in a container.

Awesome Lists containing this project

README

        

# docker_child_process

A simple docker agent at NodeJS to run scripts in a container.

## Installation

Using [npm](https://npmjs.com):

```sh
$ npm install docker_child_process
```

In NodeJS:

```ts
import { createInterface } from "docker_child_process";

const dockerInstance = createInterface();

await dockerInstance.init();

await dockerInstance.exec(`echo ok`);
// # Docker: ok

const { outputs } = await dockerInstance.exec(`echo "###=> FOO=VAZ"`);

outputs; // => { FOO: "VAZ" }

const { outputs } = await dockerInstance.exec(
`echo '###=> FOO={ "VAZ": "BIZ" }'`
);

outputs; // => { FOO: { VAZ: "BIZ" } }

const { outputs } = await dockerInstance.exec(
`echo "### => lodash=$(npm search lodash --json -p | jq '.[0]' -r --indent 0)"`
);

outputs; // => { lodash:{"name":"lodash","scope":"unscoped","version":"4.17.21","description":"Lodash modular utilities.","keywords":["modules","stdlib","util"],"date":"2021-02-20T15:42:16.891Z","links":{"npm":"https://www.npmjs.com/package/lodash","homepage":"https://lodash.com/","repository":"https://github.com/lodash/lodash","bugs":"https://github.com/lodash/lodash/issues"},"author":{"name":"John-David Dalton","email":"[email protected]","username":"jdalton"},"publisher":{"username":"bnjmnt4n","email":"[email protected]"},"maintainers":[{"username":"mathias","email":"[email protected]"},{"username":"jdalton","email":"[email protected]"},{"username":"bnjmnt4n","email":"[email protected]"}]} }
```

## Copy files

To copy a file into the container, it's posible to call the `Instance.prototype.cp()` function.

```ts
const localFile = new URL("file", import.meta.url);
await dockerInstance.cp(localFile, "file");
```