How to get started with dockerode

a 夏天 提交于 2019-12-12 17:55:30

问题


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:


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.



来源:https://stackoverflow.com/questions/39948747/how-to-get-started-with-dockerode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!