# @linzjs/docker-command

> Run a command in either docker or on you local system

Latest version **8.0.0** (published 2025-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @linzjs/docker-command
pnpm add @linzjs/docker-command
yarn add @linzjs/docker-command
bun add @linzjs/docker-command
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2025-05-11 |
| First published | 2021-02-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 24.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 128 |
| Author | Land Information New Zealand |
| Maintainers | linzds, blacha, philals |

## Links

- npm: https://www.npmjs.com/package/@linzjs/docker-command
- Repository: https://github.com/linz/basemaps
- Homepage: https://github.com/linz/basemaps#readme
- Issues: https://github.com/linz/basemaps/issues
- npm.io page: https://npm.io/package/@linzjs/docker-command

## Recent versions

- 8.0.0 (latest) — 2025-05-11
- 7.5.0 — 2024-07-02
- 7.1.0 — 2024-03-25
- 7.0.0 — 2023-11-27
- 6.32.1 — 2022-07-28
- 6.28.1 — 2022-06-07
- 6.28.0 — 2022-06-07
- 6.21.1 — 2022-03-17
- 6.10.0 — 2021-09-22
- 6.9.1 — 2021-09-09
- 6.0.0 — 2021-06-21
- 5.0.0 — 2021-05-17
- 4.22.0 — 2021-03-08
- 4.20.0 — 2021-02-15

## README

## @linzjs/docker-command

Run a command in either docker or on you local system

```typescript
import { Command } from '@linzjs/docker-command';

const cmd = new Command('echo', { container: 'ubuntu', tag: 'latest' });

// Spawn a docker container and run `echo hello world`
await cmd.create().arg('Hello World').run(); // {stdout: "Hello World\n"}
// Spawn a echo process and run `echo hello world`
await cmd.create({ useDocker: false }).arg('Hello World').run(); // {stdout: "Hello World\n"}
```

## Mounting folders in docker

folders can be mounted into the docker container volumes with `.mount`

`.mount(path)` will create a single `--volume path:path`

```typescript
import { Command } from '@linzjs/docker-command';

const proc = await Command.create('ls', { container: 'ubuntu' });
proc.mount('/home/blacha');
proc.arg('/home/blacha');

await proc.run(); // ls results for local /home/blacha
```

## Passing environment variables

```typescript
import { Command } from '@linzjs/docker-command';

const proc = await Command.create('env', { container: 'ubuntu' });
proc.env('AWS_ACCESS_KEY_ID'); // Load process.env.AWS_ACCESS_KEY_ID into docker
proc.env('AWS_ACCESS_KEY_ID', 'fakeKey'); // set a specific AWS_ACCESS_KEY_ID into docker
```

---
_Source: https://npm.io/package/@linzjs/docker-command · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
