npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@techteamer/docker-manager-library

v1.1.0

Published

A library by FaceKom to manage Docker.

Downloads

9

Readme

FaceKom Docker Manager

This library is for managing docker and docker compose services and containers.

Features

  • Container management (create, start, stop, list)
  • Image pulling
  • Docker Compose operations (create, update, up, down)
  • Container filtering by labels

Usage

[!WARNING] When updating the labels of a container, the container will be recreated, wiping the internal volume

Docker

import { DockerManager } from '@techteamer/docker-manager-library';

const dockerManager = new DockerManager();

// Start a container
await dockerManager.containerStart('container-id');

// Create and start a new container
await dockerManager.containerCreate({
  Image: 'nginx',
  Name: 'my-nginx',
  Start: true
});

// Create and start a new container with specific options
const newContainer = await dockerManager.containerCreate({
  Image: 'mongo:latest',
  Name: 'my-mongodb',
  ExposedPorts: {
    '27017/tcp': {},
  },
  HostConfig: {
    PortBindings: {
      '27017/tcp': [{ HostPort: '27017' }],
    },
  },
  Start: true,
  Labels: {
    example: 'label',
  },
})

console.log('New container created:', newContainer.id);

// List all running containers
const runningContainers = await dockerManager.getContainers(false, ['running']);
console.log('Running containers:', runningContainers);

// Get status of a specific container
const status = await dockerManager.getContainerStatus('container-id');
console.log('Container status:', status);

// Get container by a label
const containers = await dockerManager.getContainersByLabels({
  'com.docker.compose.service': 'web',
})
console.log('Containers:', containers);

// Update container labels
container = await dockerManager.containerUpdateLabels('container-id', {
  'com.docker.compose.service': 'test',
})

// Stop a container
await dockerManager.containerStop('container-id');

Docker Compose

[!NOTE] In the compose file the placeholder syntax is: {{PLACEHOLDER}}

import { DockerManager } from '@techteamer/docker-manager-library';

const dockerManager = new DockerManager();

// Work with Docker Compose
await dockerManager.composeUp('/path/to/docker-compose.yml', 'my-project');

// List containers associated with a Docker Compose project
const projectContainers = await dockerManager.composeGetContainers('myproject');
console.log('Project containers:', projectContainers);

// Stop and remove services defined in a Docker Compose file
await dockerManager.composeDown('./docker-compose.yml', 'myproject');

// Create a new Docker Compose file with placeholders
await dockerManager.composeCreate(
  './templates/docker-compose.yml',
  './docker-compose.yml',
  {
    DB_PASSWORD: 'mysecretpassword',
    VOLUME_PATH: '/data/myapp'
  }
);

// Update an existing Docker Compose file
await dockerManager.composeUpdate('./docker-compose.yml', {
  services: {
    webapp: {
      image: 'myapp:v2',
      environment: {
        DEBUG: 'true'
      }
    }
  }
});

Options

The constructor of DockerManager has the following options:

type DockerOptions = {
  socketPath?: string | undefined
  host?: string | undefined
  port?: number | string | undefined
  username?: string | undefined
  headers?: { [name: string]: string }
  ca?: string | string[] | Buffer | Buffer[] | undefined
  cert?: string | string[] | Buffer | Buffer[] | undefined
  key?: string | string[] | Buffer | Buffer[] | KeyObject[] | undefined
  protocol?: 'https' | 'http' | 'ssh' | undefined
  timeout?: number | undefined
  version?: string | undefined
  sshAuthAgent?: string | undefined
  sshOptions?: ConnectConfig | undefined
  Promise?: typeof Promise | undefined
}

Example:

const dockerManager = new DockerManager({ socketPath: '/var/run/docker.sock' })

Development

Install the dependencies

pnpm i

To run tests

pnpm test