docker-companion
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

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

( We welcome contributions 😃🎉 )

Package Sidebar

Install

npm i docker-companion

Weekly Downloads

2

Version

0.1.2

License

MIT

Unpacked Size

20.3 kB

Total Files

9

Last publish

Collaborators

  • yubert