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

@fnet/container-cmd-builder

v0.1.11

Published

This project provides a straightforward utility to help you generate Docker or Podman command-line instructions for managing containers. It takes a set of parameters as input and outputs command strings that you can use to create, control, and interact wi

Downloads

724

Readme

@fnet/container-cmd-builder

This project provides a straightforward utility to help you generate Docker or Podman command-line instructions for managing containers. It takes a set of parameters as input and outputs command strings that you can use to create, control, and interact with containers using either Docker or Podman.

How It Works

The utility accepts an object with various configuration options such as the container image, name, port and volume mappings, environment variables, and more. Based on these inputs, it constructs commands that cater to different lifecycle operations for a container, like running, starting, stopping, or inspecting it. The focus is on automating the generation of these commands to streamline the container management process.

Key Features

  • Container Runtime Support: Works with both Podman (default) and Docker.
  • Command Generation: Produces a variety of management commands including run, start, stop, pause, exec, inspect, and more.
  • Customizable Options: Allows detailed configuration with options for ports, volumes, environment variables, network settings, resource limits, and security settings.
  • Lifecycle Management: Provides commands for controlling the full lifecycle of a container.

Conclusion

This utility simplifies the process of generating command-line instructions for managing containers with Docker or Podman. It enables users to efficiently configure and control container environments by automating command creation, thus making container management less error-prone and more accessible.

@fnet/container-cmd-builder Developer Guide

Overview

The @fnet/container-cmd-builder library assists developers in generating command-line instructions for managing container lifecycles using either Docker or Podman. It simplifies the creation of commands needed to run, manage, and interact with containers. This library is designed for developers who want to automate container operations programmatically with ease.

Installation

To include the @fnet/container-cmd-builder library in your project, use npm or yarn as follows:

npm install @fnet/container-cmd-builder

or

yarn add @fnet/container-cmd-builder

Usage

Here's a step-by-step guide to using the library with real-world applications. The library allows for the configuration and generation of commands based on user inputs, making container management straightforward.

Example Usage

Below is an example of how to use the library to create commands for container operations:

import createContainerCommands from '@fnet/container-cmd-builder';

// Configuration object for the container
const config = {
  image: 'nginx', // Container image
  containerName: 'my-nginx-container', // Name of the container
  ports: [[8080, 80]], // Port mapping
  volumes: [['/local/path', '/container/path']], // Volume mapping
  env: { ENV_VAR: 'value' }, // Environment variables
  detached: true, // Run in detached mode
  runtime: 'docker', // Use Docker as the runtime
};

// Generate container commands
const commands = createContainerCommands(config);

// Output the 'run' command
console.log(commands.run); // Output: docker run -d --name my-nginx-container -p 8080:80 -v "/local/path":"/container/path" -e ENV_VAR="value" nginx

Examples

Running a Container

To run a container using the generated command:

const runCommand = commands.run;
console.log(runCommand); // Outputs the complete 'run' command for execution

Stopping a Container

To stop the running container:

const stopCommand = commands.stop;
console.log(stopCommand); // Outputs 'docker stop my-nginx-container'

Removing a Container

To remove the container:

const removeCommand = commands.remove;
console.log(removeCommand); // Outputs 'docker rm my-nginx-container'

Customizing Commands

You can customize commands using additional options:

const pauseCommand = commands.pauseWith('--time=5');
console.log(pauseCommand); // Outputs 'docker pause --time=5 my-nginx-container'

Acknowledgement

This library provides a straightforward API for developers to interact with containers using common runtime environments like Docker and Podman. Contributions from the community and the maintainers have ensured that this tool remains concise and useful for everyday container management tasks.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  image:
    type: string
    description: The container image to be used.
  containerName:
    type: string
    description: Optional name for the container.
  ports:
    type: array
    description: Array of port mappings as [hostPort, containerPort].
    items:
      type: array
      minItems: 2
      maxItems: 2
      items:
        type: number
  volumes:
    type: array
    description: Array of volume mappings as [hostPath, containerPath].
    items:
      type: array
      minItems: 2
      maxItems: 2
      items:
        type: string
  env:
    type: object
    description: Environment variables as key-value pairs.
    additionalProperties:
      type: string
  labels:
    type: object
    description: Labels as key-value pairs.
    additionalProperties:
      type: string
  detached:
    type: boolean
    description: Run the container in detached mode if true.
    default: true
  command:
    type: array
    description: Additional commands to run inside the container.
    items:
      type: string
  runtime:
    type: string
    description: Container runtime, either 'podman' (default) or 'docker'.
    default: podman
  restartPolicy:
    type: string
    description: Restart policy for the container (e.g., 'always', 'on-failure').
  network:
    type: string
    description: Network mode to use (e.g., 'bridge', 'host').
  logDriver:
    type: string
    description: Log driver to use for the container.
  logOptions:
    type: object
    description: Logging options with key-value pairs.
    additionalProperties:
      type: string
  cpuLimit:
    type: number
    description: CPU limit for the container.
  memoryLimit:
    type: string
    description: Memory limit for the container.
  securityOptions:
    type: array
    description: Security options for the container.
    items:
      type: string
required:
  - image
  - containerName