当我尝试使用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 Dockerfile
和tar软件包创建Dockerfile.tar,但是创建tar文件的方式并不重要。它不起作用。而且我的tar文件还可以。注意:Dockerfile.tar
不会打扰Docker API。我认为我的代码是错误的。
如果我使用Postman发送此请求,则将创建Docker映像。
我不明白我的代码有什么问题。欢迎所有解决方案。