🐳 🐕
docker-companion docker-companion
is a node package for asynchronously managing lifecycle and execution of docker containers.
Prerequisites
You must have the following installed to run docker-companion
:
- node 16 or higher
- docker
Additionally, typescript users can utilise the built-in typings.
Install
npm i docker-companion
Quick Start
Definitions
import { build } from "docker-companion";
import { resolve } from "path";
import { readFileSync } from "fs";
const TempDir = resolve("temp");
Build and start a container
const container = await build({
image: "alpine:3.14.0",
runOpts: ["-it"],
volumes: [[TempDir, "/usr/local/tmp"]],
}).start();
Execute a command
const { out } = await container.execute(["echo", "hello"]);
console.log(out); // "hello"
Oops, error!
const { err } = await container.execute(["ls", "nothing"]);
console.log(err); // "ls: nothing: No such file or directory"
Write to shared volume
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"
Stop the container
await container.stop();
Contributors
-
ron-aharoni
🦆 -
yuvalb
🦜
( We welcome contributions