使用Docker API和node.js构建映像

时间:2020-09-27 05:06:26

标签: node.js docker axios dockerfile docker-swarm

当我尝试使用Docker API构建映像时,抛出此错误:Cannot locate specified Dockerfile: Dockerfile。我这样编码:

// axios.post(`/build`, await fs.createReadStream('Dockerfile.tar'), { I tried this one too
// axios.post(`/build`, await fs.createReadStream('Dockerfile.tar', { encoding: 'binary' }), { I tried this one too
axios.post(`/build`, await fs.promises.readFile('Dockerfile.tar'), {
  headers: { 
    'Content-Type': 'application/x-tar'
  },
  params: {
    't': 'php:v1'
  }
}).then(data => console.log(data)).catch(error => {
  if (error) {
    console.error(error.response.status);
    console.error(error.response.data.message)
  };
});

我使用tar cfv Dockerfile.tar Dockerfiletar软件包创建Dockerfile.tar,但是创建tar文件的方式并不重要。它不起作用。而且我的tar文件还可以。注意:Dockerfile.tar不会打扰Docker API。我认为我的代码是错误的。

如果我使用Postman发送此请求,则将创建Docker映像。 this is how I send Dockerfile.tar using Postman

我不明白我的代码有什么问题。欢迎所有解决方案。

0 个答案:

没有答案