CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-dockerode

Docker Remote API module for Node.js providing programmatic interface to Docker containers, images, volumes, networks, and services.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

index.mddocs/

Dockerode

Dockerode is a comprehensive Node.js library that provides a complete interface to Docker's Remote API. It enables programmatic interaction with Docker containers, images, volumes, networks, and other Docker entities through both callback and Promise-based interfaces. The library maintains stream compatibility and includes entity-based architecture where containers, images, and exec instances are treated as first-class objects.

Package Information

  • Package Name: dockerode
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install dockerode

Core Imports

const Docker = require('dockerode');

For ES modules:

import Docker from 'dockerode';

Basic Usage

const Docker = require('dockerode');

// Create Docker client instance
const docker = new Docker();

// List all containers
const containers = await docker.listContainers({ all: true });

// Create and start a container
const container = await docker.createContainer({
  Image: 'ubuntu:latest',
  Cmd: ['/bin/bash'],
  name: 'my-container'
});

await container.start();

// Get container information
const info = await container.inspect();
console.log(info.State.Status);

Architecture

Dockerode is built around several key components:

  • Docker Client: Main entry point providing factory methods and high-level operations
  • Entity Objects: Container, Image, Volume, Network, Service, Plugin, Secret, Config, Task, Node, and Exec classes
  • Stream Support: Built-in streaming for operations that handle large amounts of data
  • Dual Interface: Supports both callback and Promise-based programming patterns
  • Modem Layer: Uses docker-modem for HTTP communication with Docker daemon
  • Swarm Support: Complete Docker Swarm management capabilities

Capabilities

Docker Client

Main Docker client providing factory methods, listing operations, creation methods, and system information.

class Docker {
  constructor(opts?: DockerOptions);
  
  // Factory methods
  getContainer(id: string): Container;
  getImage(name: string): Image;
  getVolume(name: string): Volume;
  getNetwork(id: string): Network;
  getService(id: string): Service;
  
  // System information
  info(opts?: object, callback?: Function): Promise<object>;
  version(opts?: object, callback?: Function): Promise<object>;
  ping(opts?: object, callback?: Function): Promise<string>;
}

interface DockerOptions {
  socketPath?: string;
  host?: string;
  port?: number;
  ca?: string;
  cert?: string;
  key?: string;
  protocol?: string;
  timeout?: number;
  version?: string;
  Promise?: any;
}

Docker Client Operations

Container Management

Complete container lifecycle management including creation, execution, monitoring, and file operations.

class Container {
  id: string;
  
  inspect(opts?: object, callback?: Function): Promise<object>;
  start(opts?: object, callback?: Function): Promise<object>;
  stop(opts?: object, callback?: Function): Promise<object>;
  remove(opts?: object, callback?: Function): Promise<object>;
  logs(opts?: object, callback?: Function): Promise<Stream>;
  exec(opts: ExecOptions, callback?: Function): Promise<Exec>;
}

interface ExecOptions {
  AttachStdout?: boolean;
  AttachStderr?: boolean;
  AttachStdin?: boolean;
  DetachKeys?: string;
  Tty?: boolean;
  Cmd: string[];
  Env?: string[];
  Privileged?: boolean;
  User?: string;
  WorkingDir?: string;
}

Container Operations

Image Management

Image operations including pulling, building, pushing, and inspection.

class Image {
  id: string;
  
  inspect(opts?: object, callback?: Function): Promise<object>;
  history(callback?: Function): Promise<object[]>;
  push(opts?: object, callback?: Function, auth?: object): Promise<Stream>;
  tag(opts: TagOptions, callback?: Function): Promise<object>;
  remove(opts?: object, callback?: Function): Promise<object[]>;
}

interface TagOptions {
  repo: string;
  tag?: string;
  force?: boolean;
}

Image Operations

Volume and Network Management

Docker volume and network management capabilities.

class Volume {
  name: string;
  inspect(opts?: object, callback?: Function): Promise<object>;
  remove(opts?: object, callback?: Function): Promise<object>;
}

class Network {
  id: string;
  inspect(opts?: object, callback?: Function): Promise<object>;
  remove(opts?: object, callback?: Function): Promise<object>;
  connect(opts: ConnectOptions, callback?: Function): Promise<object>;
  disconnect(opts: DisconnectOptions, callback?: Function): Promise<object>;
}

Volume and Network Operations

Docker Swarm

Complete Docker Swarm management including services, nodes, secrets, and configs.

class Service {
  id: string;
  inspect(opts?: object, callback?: Function): Promise<object>;
  update(auth?: object, opts?: object, callback?: Function): Promise<object>;
  remove(opts?: object, callback?: Function): Promise<object>;
  logs(opts?: object, callback?: Function): Promise<Stream>;
}

// Swarm management methods on Docker client
docker.swarmInit(opts: SwarmInitOptions, callback?: Function): Promise<object>;
docker.swarmJoin(opts: SwarmJoinOptions, callback?: Function): Promise<object>;
docker.swarmLeave(opts?: object, callback?: Function): Promise<object>;

Docker Swarm Operations

Plugin Management

Docker plugin lifecycle and configuration management.

class Plugin {
  name: string;
  inspect(opts?: object, callback?: Function): Promise<object>;
  enable(opts?: object, callback?: Function): Promise<object>;
  disable(opts?: object, callback?: Function): Promise<object>;
  remove(opts?: object, callback?: Function): Promise<object>;
  upgrade(auth?: object, opts?: object, callback?: Function): Promise<Stream>;
}

Plugin Operations

Static Class References

All entity classes are exposed as static properties on the Docker class for direct instantiation:

Docker.Container = Container;
Docker.Image = Image;
Docker.Volume = Volume;
Docker.Network = Network;
Docker.Service = Service;
Docker.Plugin = Plugin;
Docker.Secret = Secret;
Docker.Config = Config;
Docker.Task = Task;
Docker.Node = Node;
Docker.Exec = Exec;

Common Patterns

Callback vs Promise Support

All methods support both callback and Promise patterns:

// Callback style
docker.listContainers((err, containers) => {
  if (err) throw err;
  console.log(containers);
});

// Promise style  
docker.listContainers()
  .then(containers => console.log(containers))
  .catch(err => console.error(err));

// Async/await style
const containers = await docker.listContainers();

AbortSignal Support

Many methods support AbortSignal for request cancellation:

const controller = new AbortController();
docker.listContainers({ abortSignal: controller.signal });

// Cancel the request
controller.abort();

Stream Handling

Methods returning large amounts of data support streaming:

// Container logs as stream
const logStream = await container.logs({ 
  stdout: true, 
  stderr: true, 
  follow: true 
});

logStream.on('data', chunk => {
  console.log(chunk.toString());
});

Install with Tessl CLI

npx tessl i tessl/npm-dockerode

docs

container.md

docker-client.md

image.md

index.md

plugin.md

swarm.md

volume-network.md

tile.json