How to get started with dockerode

2019-07-13 17:27发布

I am planning on running my app in docker. I want to dynamically start, stop, build, run commands, ... on docker container. I found a tool named dockerode. Here is the project repos. This project has doc, but I am not understanding very well. I would like to understand few thing. This is how to build an image

docker.createContainer({Image: 'ubuntu', Cmd: ['/bin/bash'], name: 'ubuntu-test'}, function (err, container) {
  container.start(function (err, data) {
    //...
  });
});

It is possible to make RUN apt-get update like when we use Dockerfile, or RUN ADD /path/host /path/docker during build ? how to move my app into container after build ?

Let's see this code :

//tty:true
docker.createContainer({ /*...*/ Tty: true /*...*/ }, function(err, container) {

  /* ... */

  container.attach({stream: true, stdout: true, stderr: true}, function (err, stream) {
    stream.pipe(process.stdout);
  });

  /* ... */
}

How can I know how many params I can put here { /*...*/ Tty: true /*...*/ } ?

Has someone tried this package too ? please help me to start with.

1条回答
贪生不怕死
2楼-- · 2019-07-13 18:32

Dockerode is just a node wrapper for Docker API. You can find all params you can use for each command in api docs. For example docker.createContainer will call POST /containers/create (docs are here: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/create-a-container) Check files in lib folder of dockerode repo to see what api command is wrapped for each dockerode method.

查看更多
登录 后发表回答