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

@grucloud/docker-axios

v12.14.1

Published

Docker node client based on Axios

Downloads

10

Readme

Node client library for Docker

A lean implementation of a node client targeting the Docker API.

npm i @grucloud/docker-axios
  • Based on axios for commnucation with the docker API: UNIX socket and HTTP
  • Implemented with the amazing functional programming library rubico, a better alternative to lodash and ramda.

Setup

Create a Docker client

Import the DockerClient from @grucloud/docker-axios.

Create a client with options. These options are forwarded to axios

const { DockerClient } = require("@grucloud/docker-axios");

const docker = DockerClient({
  baseURL: "http://localhost/v1.40",
  socketPath: "/var/run/docker.sock",
  timeout: 15e3,
});

Container API

Examples of the docker container API:

  • list
  • create
  • start
  • wait
  • delete

Create a container

Please refer to the offical ContainerCreate documentation for a detailed list of the parameter.

const { v4: uuidv4 } = require("uuid");
const path = require("path");

const containerImage = "grucloud-aws";
const localVolume = "volume";
const localVolumePath = path.resolve(localVolume);
const containerName = `${containerImage}-${uuidv4()}`;

const createParam = {
  name: containerName,
  body: {
    Image: containerImage,
    Cmd: ["help"],
    HostConfig: {
      Binds: [`${localVolumePath}:/app/output`],
    },
  },
};
const result = await docker.container.create(createParam);
assert(result.Id);

Start a container

Start a container by name, options in ContainerStart

const startParam = {
  name: containerName,
};
await docker.container.start(startParam);

Wait for a container

Wait for a container to finished.

const waitParam = {
  name: containerName,
};
const result = await docker.container.wait(waitParam);
assert.equal(result.StatusCode, 0);

List containers

List all containers, options defined in ContainerList

const result = await docker.container.list({});

List a container by name:

const result = await docker.container.list({
  filters: `{"name": ["${containerName}"]}`,
});
assert.equal(result.length, 1);

Get container detail

Get a container details, options defined in ContainerInspect

const result = await docker.container.get({ id: "container id" });
assert(result.State.Status);

Retrieve container logs

Obtaint the logs from the container by name. See all options at ContainerLogs

const logParam = {
  name: containerName,
  options: {
    stdout: 1,
    stderr: 1,
    //tail: 100,
    //follow: 0,
  },
};
const stream = await docker.container.log(logParam);
stream.on("data", (data) => {
  console.log(data.toString());
});
stream.on("close", () => {});
stream.on("error", () => {});

Destroy a container

Delete a container by name, options in ContainerDelete

const destroyParam = {
  name: containerName,
};
await docker.container.delete(destroyParam);