AgustinCB / docker-api

Docker Remote API driver for node.js. It uses the same modem than dockerode, but the interface is promisified and with a fancier syntax.
GNU General Public License v3.0
306 stars 50 forks source link

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

Closed frxstrem closed 7 years ago

frxstrem commented 7 years ago

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.

AgustinCB commented 7 years ago

That's a cool catch. I'll make a fix for it today night. Thank you!

AgustinCB commented 7 years ago

Uhm, this is curious. I'm not able to reproduce your example.

The file I'm using to try:

const Docker = require('../lib/docker').Docker

const password = 'abcdef';
const database = 'test_db';
const username = 'test_user';
const port = '1234';
const docker = new Docker({ socketPath: '/var/run/docker.sock' })

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,
                                      },
                          ],
                },
        },
})
.then(mysqlContainer => mysqlContainer.start())
.then(_ => console.log("HOLA"));

I can see the "HOLA" and the container running. Same docker version, node version 7.8.

Can you put me working example of the error, please?

Sorry for the trouble!

AgustinCB commented 7 years ago

Can you also give me the result of the command docker info, please?

AgustinCB commented 7 years ago

Forget what I said, TravisCI was able to reproduce: https://travis-ci.org/AgustinCB/docker-api/builds/217519653

Thank you Travis :).

frxstrem commented 7 years ago

In case you still need it (since I already made the output files), I reproduced again (with Node 7.7.3 and 7.8.0) with your code above (just replaced the require statement with node-docker-api): https://gist.github.com/anonymous/df9f0446e42d275db44acac66abb4b25

AgustinCB commented 7 years ago

Build https://travis-ci.org/AgustinCB/docker-api/builds/217521435 passed after this little fix: https://github.com/AgustinCB/docker-api/commit/53221bfcfa0d50455cf01268d3c8067291f08b03.

I published the change as 1.1.8. Can you double check it works ok now?

Thank you again for the catch.

I'm curious why I wasn't able to reproduce in my system...

frxstrem commented 7 years ago

It's curious (it was reproducible on both my machine running Linux Mint, and my collegues, running OS X) but I ran the code again with 1.1.8 and it seems to be working now!

Thanks a lot!

AgustinCB commented 7 years ago

You're welcome, glad it worked.