https://github.com/cdaringe/run-container
run a docker container in nodejs, as concisely as possible :whale:
https://github.com/cdaringe/run-container
container docker dockerode node run
Last synced: 10 months ago
JSON representation
run a docker container in nodejs, as concisely as possible :whale:
- Host: GitHub
- URL: https://github.com/cdaringe/run-container
- Owner: cdaringe
- Created: 2018-12-19T03:54:27.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-28T00:57:26.000Z (almost 2 years ago)
- Last Synced: 2024-05-28T10:39:58.146Z (almost 2 years ago)
- Topics: container, docker, dockerode, node, run
- Language: TypeScript
- Homepage:
- Size: 1.95 MB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# run-container
run a docker container in nodejs
runs a container using [dockerode](https://www.npmjs.com/package/dockerode), bootstrapping the pull & start processes, whilst also exposing a compact function to simplify docker's and dockerode's otherwise complex APIs
[](https://www.typescriptlang.org)
[](https://github.com/semantic-release/semantic-release)
[](https://circleci.com/gh/cdaringe/run-container)
## usage
```ts
import { run, runSimple } from "run-container";
// runSimple, minimal example
const container = await runSimple({ image: "postgres" }); // => Dockerode.Container instance
await container.remove({ force: true });
// runSimple, rich example
await runSimple({
autoRemove: true,
bindMounts: { "/path/to/host/file.sh": "/path/to/container/file.sh" },
cmd: ["bash", "/path/to/container/file.sh"],
env: { KEY: "VALUE" },
image: "bash",
name: "script-fun",
ports: { "4000": "4000" }, // tcp ports only. otherwise, use `run`
});
await container.wait();
await container.remove();
// run
// exposes Dockerodes.ContainerCreateOptions full API,
// which directly reflects the docker engine API!
// https://docs.docker.com/engine/api/latest/
const container = await run({
Image: "postgres",
ExposedPorts: {
"5432/tcp": {},
},
HostConfig: {
AutoRemove: true,
PortBindings: { "5432/tcp": [{ HostPort: "40000" }] },
},
});
// ... do work
await container.remove({ force: true });
```
see the [exported typescript typings in the docs folder](https://github.com/cdaringe/run-container/tree/master/docs), or check out the tiny source.