docker-companion
Version:
A package for managing lifecycle and execution of docker containers.
85 lines (56 loc) • 1.48 kB
Markdown
`docker-companion` is a node package for asynchronously managing lifecycle and execution of docker containers.
You must have the following installed to run `docker-companion`:
- node 16 or higher
- docker
Additionally, typescript users can utilise the built-in typings.
```sh
npm i docker-companion
```
```ts
import { build } from "docker-companion";
import { resolve } from "path";
import { readFileSync } from "fs";
const TempDir = resolve("temp");
```
```ts
const container = await build({
image: "alpine:3.14.0",
runOpts: ["-it"],
volumes: [[TempDir, "/usr/local/tmp"]],
}).start();
```
```ts
const { out } = await container.execute(["echo", "hello"]);
console.log(out); // "hello"
```
```ts
const { err } = await container.execute(["ls", "nothing"]);
console.log(err); // "ls: nothing: No such file or directory"
```
```ts
await container.execute([
"sh",
"-c",
`echo -e -n hello > /usr/local/tmp/hello.txt`,
]);
const localFile = resolve(TempDir, "hello.txt");
const content = readFileSync(localFile);
console.log(content); // "hello"
```
```ts
await container.stop();
```
- [ron-aharoni](https://github.com/ron-aharoni) 🦆
- [yuvalb](https://github.com/yuvalb) 🦜
( We welcome contributions 😃🎉 )