Giter Site home page Giter Site logo

agustincb / docker-api Goto Github PK

View Code? Open in Web Editor NEW
301.0 301.0 52.0 1.31 MB

Docker Remote API driver for node.js. It uses the same modem than dockerode, but the interface is promisified and with a fancier syntax.

License: GNU General Public License v3.0

JavaScript 17.35% Shell 1.05% TypeScript 81.60%

docker-api's People

Contributors

dcharbonnier avatar denbon05 avatar dependabot[bot] avatar dsbudiac avatar gilesvangruisen avatar jinxidoru avatar martinmeinhold avatar omgimalexis avatar phoenix741 avatar sabrehagen avatar stouf avatar tienne avatar williamoverton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

docker-api's Issues

Getting an error while building an image

@AgustinCB
Getting the error "TypeError: data.pipe is not a function" While building an image
please find the code below

const Docker = require('node-docker-api').Docker;
const docker = new Docker({
    socketPath: '/var/run/docker.sock'
});

async function runDockerImage() {
        await docker.image.build({t: 'writl/sftp'});
}

Docker Stack Missing

Is this project still supported? It seems that the new Docker Swarm capabilities are missing, i.e. commands such as docker stack ls are not implemented. Is this planned?

Currently, I use child_process to execute docker commands in nodejs, but your approach using the API is more elegant, so I'd like to switch to your library. This is my project wher eI would like to use your library: mwaeckerlin/docker.js

Error on pulling

I tried the example for pulling images

 docker.image.create({ fromImage: 'ubuntu' })
    .then((stream) => promisifyStream(stream))
    .then(() => docker.image.status('ubuntu'))
    .then((image) => image.history())
    .then((events) => console.log(events))

However, I've seen that when you don't consume the stream, as is the case in your example, the end event is never fired.

When I log the data of the promisified stream, I get:

{"status":"Downloading from http://"}
{"errorDetail":{"message":"Get http://: http: no Host in request URL"},"error":"Get http://: http: no Host in   request URL"}

You have to remove (or rename) that container to be able to reuse that name.

{ Error: (HTTP code 409) unexpected - Conflict. The container name "/test" is already in use by container "70f415ef635ece943bee6c935f78b0912a88573e95ab8f7fe9d24d397e5e8379". You have to remove (or rename) that container to be able to reuse that name.

It is taking some time to delete the container(1000 ms). How to resolve this.

docker.container.list()
                   .then(containers => containers.forEach(function(value, i) {
                       if (value.data.Names.includes('/test')) {
                           value.delete({force: true})
                       }
                   })).then( docker.container.create({
                               Image: '**',
                               name: 'test',
                               Env: [  ],
                               "HostConfig": {
                                   "NetworkMode": "host"
                               }
                           })
                           .then(container => container.start())
                           .catch(error => console.log(error)));

Help using docker.service.update()

Hi, trying to understand how to use this method? The docker api needs version in query string and Spec in Post body. Do you have any examples? I'm not a native js programmer and I'm not sure how I should be calling:
var version = service.data["Version"]["Index"];
service.data.Spec.Mode.Replicated.Replicas=update_count;
service.update({version: version})
.catch(error => console.log(error));

gives
{ Error: (HTTP code 400) unexpected - rpc error: code = InvalidArgument desc = TaskSpec: missing runtime
at /etc/chef/compose-stacks/node_modules/docker-modem/lib/modem.js:239:17
at getCause (/etc/chef/compose-stacks/node_modules/docker-modem/lib/modem.js:269:7)
at Modem.buildPayload (/etc/chef/compose-stacks/node_modules/docker-modem/lib/modem.js:238:5)
at IncomingMessage. (/etc/chef/compose-stacks/node_modules/docker-modem/lib/modem.js:214:14)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
reason: undefined,
statusCode: 400,
json:
{ message: 'rpc error: code = InvalidArgument desc = TaskSpec: missing runtime' } }

P.S. - Just saw this, seems related: (docker-java/docker-java#958)
does the api version need to be updated someplace?

Need example on how to pass params

Hi!
It is not clear how to pass params to match with 'docker run' command:
how to pass port mappings, '--shm-size' etc. Please add some examples on it.

docker.service.list() empty array

when I do this I get an empty array
I am using this the correct way?

const Docker = require('node-docker-api').Docker
const docker = new Docker({
  socketPath: '/var/run/docker.sock'
})

 // GET: /services
 function serviceList(req, reply) {
   docker.service.list().then((services) => {
     console.dir(services)
     reply.sendStatus(200)
   }).catch((err) => {
     sendError(err, reply)
   })
 }

Implement Docker copy

Hey there!
I'd be great to be able to copy contents from a running container to the host or the container.
Thanks in advance.

exec in interactive mode

Hi,

How can i make an exec command with the interactive mode ??
I'm looking for a way to do docker exec -it test /bin/bash with docker api.

Thanks for helping.

Example needed 'add-host'

In my docker run command I have to use this:

--add-host=host.docker.internal:host-gateway

How can I achieve the same functionality in docker.container.create?
Right now my code looks like this:

                docker.container.create({
                    Image: 'IMAGENAME',
                    name: bot_name,
                    Env: [envChannel],
                    HostConfig: {
                        Binds: [
                            envFolder + ":" + envLogFolder
                        ]
                    }
                })

service.logs() promise hangs with --follow

The promise never resolves under the following code:

let Docker = require('node-docker-api').Docker;
let docker = new Docker();

let id = '123abc'; // service id

let opts = {
  stdout: true,
  stderr: true,
  follow: true
};

let service = docker.service.get(id);

// This promise never resolves
service.logs(opts).then(stream => {
  console.log('Found stream!');
  stream.pipe(process.stdout);
}).catch(console.error);

The promise does not hang when follow is excluded. Also, the promise resolves under this same pattern for container logs.

Auth params in constructor?

I was wondering if you would be open to adding a feature to the Docker constructor to accept auth config while still supporting and overwriting those configs if specifically passed to method?

[proposal] remove the confusion between the class and instance access

Example of implementation for the Exec class
dcharbonnier@78b2f22
The file may be easier to read container.ts

Example of use :

const container = new Container(new Modem({}), "e90e34656806");

const exec = container.exec.get(SAVER_EXEC_ID);
await exec.resize({h: 10, w : 5});
let status = await exec.status();
console.log(`This exec is ${status.Running ? "" : "not "} running`);

const execLs = await container.exec.create({ Cmd: "ls /", AttachStdout: true});
const stream = await execLs.start();
stream.on("data", (data: Buffer) => console.log(data.toString()));
stream.on("end", () => console.log("ls done"));

Is there a way to add a volume when creating or starting a container?

I'm trying to recreate this command using docker-api but I don't see anything at all about using volumes and the docs page isn't working.

docker run -d \
   -v $(pwd)/.caddy/php/Caddyfile:/etc/Caddyfile \
   -v $(pwd)/root/sites/user123/example.com/www:/srv \
   -v $(pwd)/root/sites/user123/example.com/logs:/logs \
   --name=example.com \
   abiosoft/caddy:php

container.start() doesn't work for Docker 17.03

Trying to start a container with the following code does not work:

const password = 'abcdef';
const database = 'test_db';
const username = 'test_user';
const port = '1234';

mysqlContainer = await docker.container.create({
  name: 'mysql-container',
  Image: 'mysql/mysql-server',
  Env: [
    'MYSQL_ROOT_PASSWORD=' + password,
    'MYSQL_DATABASE=' + database,
    'MYSQL_USER=' + username,
    'MYSQL_PASSWORD=' + password ],
  HostConfig: {
    PortBindings: {
      '3306/tcp': [
        {
          HostIp: '127.0.0.1',
          HostPort: port,
        },
      ],
    },
  },
});

// start container
await mysqlContainer.start();  // <-- Error here

It just gives this error:

Error: (HTTP code 400) unexpected - starting container with non-empty request body was
deprecated since v1.10 and removed in v1.12 
 at node_modules/docker-modem/lib/modem.js:239:17
 at getCause (node_modules/docker-modem/lib/modem.js:269:7)
 at Modem.buildPayload (node_modules/docker-modem/lib/modem.js:238:5)
 at IncomingMessage.<anonymous> (node_modules/docker-modem/lib/modem.js:214:14)
 at endReadableNT (_stream_readable.js:974:12)
 at _combinedTickCallback (internal/process/next_tick.js:80:11)
 at process._tickCallback (internal/process/next_tick.js:104:9)

I'm running this on Node 7.7.3, Docker 17.03.1-ce, node-docker-api v1.1.7. When running the same code with Docker 1.12.6, there is no error or unexpected behavior.

partial file written to container

.then(() => container.fs.put(`${settings.TMP}/nginx.conf`, {path: settings.NGINX_CONF_PATH}))

the end of the file is truncated

Docker version 17.04.0-ce, build 4845c56

How to filter events?

I'm trying to filter events by type=container, but this doesn't seem to work:

docker.events({
  since: ((new Date().getTime() / 1000)).toFixed(0),
  filter: {
    type: 'container'
  }
}).then(stream => {
  stream.on('data', data => {
    const event = JSON.parse(data.toString());
    logger.info(`DOCKER EVENT: Type=${event.Type} status=${event.status} from=${event.from}`);
  });
});

With the above code, I still get all event types.

service.update, remove and status is undefined

Using version 1.1.8

service.md

const Docker = require('node-docker-api').Docker
const docker = new Docker({
  socketPath: '/var/run/docker.sock'
})

typeof docker.service.update === 'undefined'
typeof docker.service.remove === 'undefined'
typeof docker.service.status === 'undefined'

Docs container.events is not a function

.then(<span class="hljs-function">(<span class="hljs-params">container</span>) =&gt;</span> container.events())

The Fetch events from docker example in docs/index.html is using container.events which throws an error. Is this an older version of the API? It doesn't match the example code in examples/fetch_events.js.

Thanks,
Russ

yarn

Do you mind moving to yarn ? It's much faster

Update documentation

It hasn't been updated since the change to add type safety. It's useless right now.

Service update asking for credentials

When I do a service update of a service that uses a private image I get an error, the error says that I don't have access to that image.
Where do i add my credentials?

Thanks!

function serviceReplicas(req, reply) {
  const id = req.swagger.params.id.value
  const replicas = req.swagger.params.replicas.value.Replicas

  docker
    .service
    .get(id)
    .status()
    .then((service) => {
      const data = service.data.Spec
      data.version = service.data.Version.Index
      data.Mode.Replicated.Replicas = replicas

      return service.update(data)
    })
    .then((response) => {
      reply.json(response.data)
    })
    .catch((err) => {
      utils.sendError(err, reply)
    })
}

Typings issues

You are writing with TS, and still typing seems to be not good, even @types/dockernode feel to have more proper typings.

Even your new Docker(/*opts: not typed*/) constructor has no typings for options, and results are typed not correctly:

image

It is not a critique, just want to draw your attention to typings issues.

How to read stream of a command executed in Docker container?

How I can read an ouput stream of a command executed in Docker container? I try to use a code from example, but 'data' event is not fired at all. What I'm doing wrong? And is it possible to get a status code (success, fail...) of a command execution? Thank you.

Code examle:

'use strict'

const Docker = require('node-docker-api').Docker

const _docker = new Docker()
let _container

const containerParams = {
	Image: 'docker-test-image',
	Tty: true
}
_docker.container.create(containerParams)
	.then((container) => container.start())
	.then((container) => {
		console.log('Container started')

		_container = container

		return _container.exec.create({
			Cmd: ['ls', '-ll']
		})
	})
	.then((exec) => {
		console.log('Exec created')

		return exec.start()
	})
	.then((stream) => {
		console.log('Container ID:', _container.id)
		console.log('Exec started')

		stream.on('readable', () => {
			console.log('onreadable')
		})
		stream.on('data', (data) => {
			console.log('Data from Docker has been obtained')
			console.log(data.toString())

			_container.kill()
		})
		stream.on('end', () => {
			console.log('onend')
		})
		stream.on('error', (err) => console.log(err))
	})
	.catch((err) =>  {
		console.log(err)
	})

Open Files Docker process

I'm using it to collect data from containers by minute.
But it's increase docker open files, the limit is 65556, and in one the the limit went from 3000 to 28000 open files...
Theres a way to collect data once? not by stream? or close the open file after read it ?

here is the code

const containers = await docker.container.list();
containers.map(async (container) => {
    const stats = await getStats(container);
    return stats;
});

const getStats = container => new Promise(async (resolve, reject) => {
  try {
    const stats = await container.stats();

    if (!stats) reject();

    stats.on('data', (stat) => {
      if (stat instanceof Buffer) {
        try {
          const statString = stat.toString();
          const json = JSON.parse(statString);
          resolve(json);
        } catch (err) {
          reject();
        }
      } else {
        reject();
      }
    });
  } catch (err) {
    reject();
    error(err);
  }
});

Example do not work

For example if I run

'use strict';
const {Docker} = require('node-docker-api');

const promisifyStream = stream => new Promise((resolve, reject) => {
  stream.on('data', data => console.log(data.toString()))
  stream.on('end', resolve)
  stream.on('error', reject)
});

const docker = new Docker({ socketPath: '/var/run/docker.sock' });
let _container;

docker.container.create({
  Image: 'ubuntu',
  Cmd: [ '/bin/bash', '-c', 'tail -f /var/log/dmesg' ],
  name: 'test'
})
  .then(container => container.start())
  .then(container => {
    _container = container
    return container.exec.create({
      AttachStdout: true,
      AttachStderr: true,
      Cmd: [ 'echo', 'test' ]
    })
  })
  .then(exec => {
    return exec.start({ Detach: false })
  })
  .then(stream => promisifyStream(stream))
  .then(() => _container.kill())
  .catch(error => console.log(error));

I get the following:

% uname -a
Darwin ME 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan  9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64
% node --version
v12.8.0
% node test.js
)cannot exec in a stopped state: unknown

how to mount "-v //var/run/docker.sock://var/run/docker.sock" in docker-api

hey,
i need some help.

how to translate cli-command "docker run --name watchtower -v //var/run/docker.sock://var/run/docker.sock v2tec/watchtower" to the docker api.

i'm trying like this. but it is not working

dockerStart.container .create({ name: "watchtower", Image: "v2tec/watchtower", Volumes:{ "/var/run/docker.sock":{'/var/run/docker.sock'}} }) .then(container=>container.start()) .catch(error => console.log(error));

Thank you for your help :)

container.logs() returns unprintable chars in buffer

Hello
I'm trying the following code with an existing container (typescript):

this.stream = await this.container.logs({ follow: true, stdout: true }) as Stream;
this.stream.on('data', (info: any) => console.log(info));

But I get things like:


<Buffer 02 00 00 00 00 00 00 60 74 69 6d 65 3d 22 32 30 32 31 2d 30 34 2d 31 37 54 30 39 3a 31 35 3a 31 38 5a 22 20 6c 65 76 65 6c 3d 77 61 72 6e 69 6e 67 20 ... >
<Buffer 02 00 00 00 00 00 00 5c 74 69 6d 65 3d 22 32 30 32 31 2d 30 34 2d 31 37 54 30 39 3a 31 35 3a 31 38 5a 22 20 6c 65 76 65 6c 3d 69 6e 66 6f 20 6d 73 67 ... >
<Buffer 02 00 00 00 00 00 00 93 74 69 6d 65 3d 22 32 30 32 31 2d 30 34 2d 31 38 54 31 34 3a 32 30 3a 32 39 5a 22 20 6c 65 76 65 6c 3d 65 72 72 6f 72 20 6d 73 ... >
<Buffer 02 00 00 00 00 00 00 53 74 69 6d 65 3d 22 32 30 32 31 2d 30 34 2d 31 38 54 31 34 3a 33 37 3a 34 38 5a 22 20 6c 65 76 65 6c 3d 65 72 72 6f 72 20 6d 73 ... >
<Buffer 02 00 00 00 00 00 00 93 74 69 6d 65 3d 22 32 30 32 31 2d 30 34 2d 31 38 54 31 34 3a 33 37 3a 34 38 5a 22 20 6c 65 76 65 6c 3d 65 72 72 6f 72 20 6d 73 ... >
<Buffer 02 00 00 00 00 00 01 11 74 69 6d 65 3d 22 32 30 32 31 2d 30 34 2d 31 38 54 31 34 3a 34 34 3a 33 39 5a 22 20 6c 65 76 65 6c 3d 65 72 72 6f 72 20 6d 73 ... >
<Buffer 02 00 00 00 00 00 00 4f 74 69 6d 65 3d 22 32 30 32 31 2d 30 35 2d 31 31 54 30 38 3a 34 37 3a 32 37 5a 22 20 6c 65 76 65 6c 3d 69 6e 66 6f 20 6d 73 67 ... >
<Buffer 02 00 00 00 00 00 00 52 74 69 6d 65 3d 22 32 30 32 31 2d 30 35 2d 31 31 54 30 38 3a 34 37 3a 32 37 5a 22 20 6c 65 76 65 6c 3d 77 61 72 6e 69 6e 67 20 ... >
<Buffer 02 00 00 00 00 00 01 61 74 69 6d 65 3d 22 32 30 32 31 2d 30 35 2d 31 31 54 30 38 3a 34 37 3a 32 37 5a 22 20 6c 65 76 65 6c 3d 69 6e 66 6f 20 6d 73 67 ... >
<Buffer 02 00 00 00 00 00 00 82 74 69 6d 65 3d 22 32 30 32 31 2d 30 35 2d 31 31 54 30 38 3a 34 37 3a 32 37 5a 22 20 6c 65 76 65 6c 3d 77 61 72 6e 69 6e 67 20 ... >
<Buffer 02 00 00 00 00 00 00 64 74 69 6d 65 3d 22 32 30 32 31 2d 30 35 2d 31 31 54 30 38 3a 34 37 3a 32 37 5a 22 20 6c 65 76 65 6c 3d 69 6e 66 6f 20 6d 73 67 ... >
<Buffer 02 00 00 00 00 00 00 60 74 69 6d 65 3d 22 32 30 32 31 2d 30 35 2d 31 31 54 30 38 3a 34 37 3a 32 37 5a 22 20 6c 65 76 65 6c 3d 77 61 72 6e 69 6e 67 20 ... >

Translated to an UTF-8 string, this gives:

    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000�time=\"2021-05-11T08:47:27Z\" level=warning msg=\"skipping containerd worker, as \\\"/run/containerd/containerd.sock\\\" does not exist\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000dtime=\"2021-05-11T08:47:27Z\" level=info msg=\"found 1 workers, default=\\\"vd8qke8qoo98y1vo3yokyssrw\\\"\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000`time=\"2021-05-11T08:47:27Z\" level=warning msg=\"currently, only the default worker can be used.\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\\time=\"2021-05-11T08:47:27Z\" level=info msg=\"running server on /run/buildkit/buildkitd.sock\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000Otime=\"2021-05-13T15:04:37Z\" level=info msg=\"auto snapshotter: using overlayfs\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000Rtime=\"2021-05-13T15:04:37Z\" level=warning msg=\"using host network as the default\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0001atime=\"2021-05-13T15:04:37Z\" level=info msg=\"found worker \\\"vd8qke8qoo98y1vo3yokyssrw\\\", labels=map[org.mobyproject.buildkit.worker.executor:oci org.mobyproject.buildkit.worker.hostname:662c0cfd0a89 org.mobyproject.buildkit.worker.snapshotter:overlayfs], platforms=[linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6]\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000�time=\"2021-05-13T15:04:37Z\" level=warning msg=\"skipping containerd worker, as \\\"/run/containerd/containerd.sock\\\" does not exist\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000dtime=\"2021-05-13T15:04:37Z\" level=info msg=\"found 1 workers, default=\\\"vd8qke8qoo98y1vo3yokyssrw\\\"\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000`time=\"2021-05-13T15:04:37Z\" level=warning msg=\"currently, only the default worker can be used.\"\n",
    "\u0002\u0000\u0000\u0000\u0000\u0000\u0000\\time=\"2021-05-13T15:04:37Z\" level=info msg=\"running server on /run/buildkit/buildkitd.sock\"\n"

The log file contains lines like this:

{"log":"time=\"2021-02-13T17:50:43Z\" level=info msg=\"auto snapshotter: using overlayfs\"\n","stream":"stderr","time":"2021-02-13T17:50:43.122733748Z"}
{"log":"time=\"2021-02-13T17:50:43Z\" level=warning msg=\"using host network as the default\"\n","stream":"stderr","time":"2021-02-13T17:50:43.122785591Z"}
{"log":"time=\"2021-02-13T17:50:43Z\" level=info msg=\"found worker \\\"vd8qke8qoo98y1vo3yokyssrw\\\", labels=map[org.mobyproject.buildkit.worker.executor:oci org.mobyproject.buildkit.worker.hostname:662
c0cfd0a89 org.mobyproject.buildkit.worker.snapshotter:overlayfs], platforms=[linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6]\"\n","stream":"stderr","time":"2021-02-
13T17:50:43.129430342Z"}
{"log":"time=\"2021-02-13T17:50:43Z\" level=warning msg=\"skipping containerd worker, as \\\"/run/containerd/containerd.sock\\\" does not exist\"\n","stream":"stderr","time":"2021-02-13T17:50:43.13793810
3Z"}
{"log":"time=\"2021-02-13T17:50:43Z\" level=info msg=\"found 1 workers, default=\\\"vd8qke8qoo98y1vo3yokyssrw\\\"\"\n","stream":"stderr","time":"2021-02-13T17:50:43.137953377Z"}
{"log":"time=\"2021-02-13T17:50:43Z\" level=warning msg=\"currently, only the default worker can be used.\"\n","stream":"stderr","time":"2021-02-13T17:50:43.137973538Z"}
{"log":"time=\"2021-02-13T17:50:43Z\" level=info msg=\"running server on /run/buildkit/buildkitd.sock\"\n","stream":"stderr","time":"2021-02-13T17:50:43.141073587Z"}
{"log":"time=\"2021-02-13T17:52:32Z\" level=error msg=\"releasing already released reference\"\n","stream":"stderr","time":"2021-02-13T17:52:32.162341911Z"}

So it seems that the beginning of each line returned by container.logs is preprended with weird unprintable chars + one printable char...

Is this a bug or am I missing something?

Image pull stream comes in batches, not one by one

I noticed today, that using promisifyStream, the messages don't come one by one.
This makes it hard to parse and work on the JSON strings of pull messages.

It looks like this when .split('\r\n')

[ '{"status":"Pulling from library/hello-world","id":"latest"}' ]
[
  '{"status":"Pulling fs layer","progressDetail":{},"id":"1b930d010525"}'
]
[
  '{"status":"Downloading","progressDetail":{"current":473,"total":977},"progress":"[========================\\u003e                          ]     473B/977B","id":"1b930d010525"}',
  '{"status":"Downloading","progressDetail":{"current":977,"total":977},"progress":"[==================================================\\u003e]     977B/977B","id":"1b930d010525"}',
  '{"status":"Verifying Checksum","progressDetail":{},"id":"1b930d010525"}',
  '{"status":"Download complete","progressDetail":{},"id":"1b930d010525"}'
]
[
  '{"status":"Extracting","progressDetail":{"current":977,"total":977},"progress":"[==================================================\\u003e]     977B/977B","id":"1b930d010525"}',
  '{"status":"Extracting","progressDetail":{"current":977,"total":977},"progress":"[==================================================\\u003e]     977B/977B","id":"1b930d010525"}'
]
[
  '{"status":"Pull complete","progressDetail":{},"id":"1b930d010525"}'
]
[
  '{"status":"Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f"}'
]
[
  '{"status":"Status: Downloaded newer image for hello-world:latest"}'
]

Is there a way to make the fn in stream.on('data', fn) only receive single objects?

Thanks in advance!

login method?

I must be overlooking it, but I cannot find the equivalent to docker login in the SDK.

I need to use docker login because I am trying to pull an image that exists in AWS ECR. I found the pull command in this SDK,

docker.image.create(...)

I found that I can get a session token from ECR using ecr.getAuthorizationToken.
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ECR.html#getAuthorizationToken-property

How can I use the token from ECR with docker login in your SDK?

Update: After more searching, I found the docker endpoint called /auth but now I am wondering how to pass it the authentication Token from ECR.
https://docs.docker.com/engine/api/v1.24/#33-misc

Update 2: I found in the docker api v 1.33 they support an identitytoken that seems like the right place to put the token from ECR.
https://docs.docker.com/engine/api/v1.33/#section/Authentication

Update 3: Piecing together the docs I have this code:

const promisifyAwsResponse = (awsResponse) => new Promise((resolve, reject) => {
    awsResponse.on('success', (res) => {
        console.log('awsResponse success:', JSON.stringify(res.data));
        resolve(res.data);
    });
    awsResponse.on('error', (err) => {
        console.error('awsResponse error:', err);
        reject(err);
    });
    awsResponse.send();
});

    const ecrParams = {
    };
    return promisifyAwsResponse(ECR.getAuthorizationToken(ecrParams))
        .then((ecrAuthResult) => {
            const ecrAuth = ecrAuthResult.authorizationData[0];
            // I just realized the first arg is for auth data
            return docker.image.create({
                    identitytoken: ecrAuth.authorizationToken,
                    serveraddress: ecrAuth.proxyEndpoint
                }, {
                    fromImage: "ecrImageName",
                    tag: 'latest'
                });
        })
      .catch((err) => console.error(err));

Unfortunately I get the same error as when I make no attempt to authenticate with ECR.

Error: (HTTP code 500) server error - Get https://omittedAccount.dkr.ecr.us-west-2.amazonaws.com/v2/omittedRepoName/manifests/latest: no basic auth credentials"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.