@hackbg/dock
v2.0.8
Published
Docker utilities.
Downloads
39
Keywords
Readme
@hackbg/dock
Want to run some operation from Node in a reproducible environment? Here's a really simple way to achieve that with containers.
Overview
This library builds upon Dockerode,
and provides the Engine
, Image
and Container
abstractions, which
make it easy and performant to package and run reproducible operations
(such as containerized builds or ETL pipelines).
- The
Engine
class connects to the Docker runtime at/var/run/docker.sock
or the path specified by theDOCKER_HOST
environment variable. - The
Image
class supports specifying both an upstream tag to pull from Docker Hub, and/or a local fallback Dockerfile. This allows for fast iteration when constructing the Dockerized runtime environment. - From an
Image
instance, you can launch one or more **Container
**s. If you like, you can run multiple parallel operations in identical contexts (as specified by a single localDockerfile
), and theImage
will build itself locally, only once and without touching Docker Hub.
Example
import Docker from '@hackbg/dock'
const engine = new Docker.Engine()
const image = engine.image(
'my-org/my-build-image:v1', // This image will be pulled
'/path/to/my/Dockerfile', // If the pull fails, build from this Dockerfile
[] // Any local paths referenced from the Dockerfile should be added here
)
const container = await image.run(`build_${+new Date()}`, {
readonly: { '/my/project/sources': '/src' }, // -v ro
writable: { '/my/project/artifacts': '/dist' }, // -v rw
mapped: { 80: 8080 } // container:host
})
Roadmap
- [ ] Support Podman for fully rootless operation
Made with #%&! @ Hack.bg