How to use dockerode - 10 common examples

To help you get started, we’ve selected a few dockerode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Casa / Casa-Node-Manager / test / endpoints / v1 / telemetry.js View on Github external
it('should have no updatable containers if one exists, but was pulled in the last 90 minutes', done => {

      clock = sinon.useFakeTimers({
        now: 1546329600000, // January 1, 2019 Midnight PST
        shouldAdvanceTime: false,
      });

      dockerodeListAllContainers = sinon.stub(require('dockerode').prototype, 'listContainers')
        .yields(null, dockerodeMocks.listAllContainers());
      dockerodeListImages = sinon.stub(require('dockerode').prototype, 'listImages')
        .yields(null, dockerodeMocks.listImagesWithUpdate());

      requester
        .get('/v1/telemetry/version')
        .set('authorization', `JWT ${token}`)
        .end((err, res) => {
          if (err) {
            done(err);
          }
          res.should.have.status(200);
          res.should.be.json;

          res.body.should.have.property('lnd');
          res.body['lnd'].updatable.should.equal(false);
          res.body.should.have.property('bitcoind');
          res.body['bitcoind'].updatable.should.equal(false);
github lando / lando / test / docker.spec.js View on Github external
it('should throw an error on all other catches', () => {
      // Our own little bad container.
      const bogusContainer = new Dockerode.Container();
      // Throw the proper error.
      const inspectStub = sinon.stub(bogusContainer, 'inspect').rejects(new Error('It\'s a trap!'));
      // Make sure we return the proper failing container.
      const getStub = sinon.stub(landerode, 'getContainer').returns(bogusContainer);

      return landerode.isRunning('foo').should.be
      .rejectedWith('It\'s a trap!').then(() => {
        getStub.restore();
        inspectStub.restore();
      });
    });
  });
github lando / lando / test / docker.spec.js View on Github external
it('should return true if State.Running inspect data is true', () => {
      // Container to return from 'getContainer';;l
      const bogusContainer = new Dockerode.Container({}, 'YT-1300');
      // Force the state of the container to be running.
      const inspectStub = sinon.stub(bogusContainer, 'inspect').resolves({
        State: {
          Running: true,
        },
      });
      // Force the return of our container
      const getStub = sinon.stub(landerode, 'getContainer').returns(bogusContainer);

      return landerode.isRunning('YT-1300').should.eventually.be.true
      .then(() => {
        inspectStub.restore();
        getStub.restore();
      });
    });
github Casa / Casa-Node-Manager / test / endpoints / v1 / settings.js View on Github external
before(() => {
    // Saving settings performs a `docker-compose up`
    dockerodeListAllContainers = sinon.stub(require('dockerode').prototype, 'listContainers')
      .yields(null, dockerodeMocks.listAllContainers());
    dockerodeListImages = sinon.stub(require('dockerode').prototype, 'listImages')
      .yields(null, dockerodeMocks.listImages());

    const dockerCompose = `${__dirname}/../../../logic/docker-compose.js`;
    dockerComposeUpStub = sinon.stub(require(dockerCompose), 'dockerComposeUpSingleService');
    dockerComposeStopStub = sinon.stub(require(dockerCompose), 'dockerComposeStop');
    dockerComposeRemoveStub = sinon.stub(require(dockerCompose), 'dockerComposeRemove');

    const lnapi = `${__dirname}/../../../services/lnapi.js`;
    unlockLndStub = sinon.stub(require(lnapi), 'unlockLnd');
  });
github catsass19 / Sapporo / server / docker.js View on Github external
'docker.info'(dockerConfig) {
            let future = new Future();
            let testDocker = new Dockerode({
                host: dockerConfig.address,
                port: dockerConfig.port
            });
            testDocker.info((err, data) => {
                if (err) {
                    future.throw('cannot connect to Docker');
                    return;
                } else {
                    future.return(data);
                }
            });
            return future.wait();
        },
        // 'docker.listImage'() {
github kevinpollet / seel / src / buildImage.ts View on Github external
const defaultBuildConfig = await getBuildConfig(absoluteDir);
  const buildConfig = overrideBuildConfig(defaultBuildConfig, options);
  const buildContext = await createBuildContext(absoluteDir, buildConfig);
  const dockerImageTags = (buildConfig.tags || []).map(
    tag => `${buildConfig.name}:${tag}`
  );

  const getDaemonMessage = new Transform({
    writableObjectMode: true,
    transform(chunk, _, callback): void {
      const { stream, error } = chunk as any; // eslint-disable-line @typescript-eslint/no-explicit-any
      callback(error ? new Error(error) : undefined, stream || undefined);
    },
  });

  return new Dockerode()
    .buildImage(buildContext, {
      t: dockerImageTags,
      buildargs: {
        AUTH_TOKEN:
          buildConfig.pkgRegistryAuth && buildConfig.pkgRegistryAuth.token,
      },
    })
    .then(daemonStream =>
      daemonStream.pipe(split2(line => JSON.parse(line))).pipe(getDaemonMessage)
    );
};
github exoframejs / exoframe-server / src / docker / docker.js View on Github external
// replace promises with bluebird
import Bluebird from 'bluebird';
import Docker from 'dockerode';

// promisify
Bluebird.promisifyAll(Docker.prototype);

// create new docker instance
const docker = new Docker(); // defaults to above if env variables are not used

// promisify network
const network = docker.getNetwork('promisify-net');
Bluebird.promisifyAll(network.constructor.prototype);
// promisify container
const container = docker.getContainer('promisify-container');
Bluebird.promisifyAll(container.constructor.prototype);
// promisify image
const image = docker.getImage('promisify-image');
Bluebird.promisifyAll(image.constructor.prototype);

export default docker;
github exoframejs / exoframe-server / src / docker / docker.js View on Github external
// replace promises with bluebird
import Bluebird from 'bluebird';
import Docker from 'dockerode';

// promisify
Bluebird.promisifyAll(Docker.prototype);

// create new docker instance
const docker = new Docker(); // defaults to above if env variables are not used

// promisify network
const network = docker.getNetwork('promisify-net');
Bluebird.promisifyAll(network.constructor.prototype);
// promisify container
const container = docker.getContainer('promisify-container');
Bluebird.promisifyAll(container.constructor.prototype);
// promisify image
const image = docker.getImage('promisify-image');
Bluebird.promisifyAll(image.constructor.prototype);

export default docker;
github ktk-2005 / Feedbacker-Forum / server / src / docker.js View on Github external
export async function createNewRunner(userId, dockerTag) {
  logger.info(`Creating new instance runner ${dockerTag}`)

  // Verify that dockerode parses the tag to be something sensible before
  // pulling the image. The Docker daemon pulls *all* available tags if one
  // isn't specified. So we verify that the tag isn't empty.
  const tagParse = parseRepositoryTag(dockerTag)
  if (!tagParse.hasOwnProperty('tag')) {
    throw new HttpError(400, 'No tag version specified')
  }

  await createNewInstanceRunner(userId, dockerTag)

  // We won't wait for the promise to resolve because
  // especially with larger images it can take a while to download.
  // Instead, we update the download's status in the database.

  // It should also be noted that this updates the image for all other
  // users too if they use the same tag.

  docker.pull(dockerTag).then(async (stream) => {
    logger.info(`Pulling image ${dockerTag}...`)
    // eslint-disable-next-line no-unused-vars
github lando / lando / test / docker.spec.js View on Github external
const dummyContainer = (overrides = {}) => {
  return _.assign(
    new Dockerode.Container(),
    {
      Id: '8675309',
      app: 'Death Star',
      Labels: {
        'com.docker.compose.project': 'Death Star',
        'com.docker.compose.service': 'Exhaust Port',
        'com.docker.compose.container-number': 73,
        'com.docker.compose.oneoff': 'no',
        'io.lando.container': 'TRUE',
        'io.lando.src': '/tmp/.lando.yml',
        'io.lando.id': 'lando',
        'io.lando.service-container': 'no',
      },
    },
    overrides
  );