构建Dockerfile Node.js时如何连接Minio

时间:2019-07-11 18:38:10

标签: node.js docker minio

当我通过Dockerfile构建项目时,无法与minio连接。按脚本节点运行项目时,一切正常。

const minioConfig = {
    endPoint: process.env.domain_minio || process.env.domain;
    port: Number(process.env.port_endPoint) || 9001,
    useSSL: false,
    accessKey: process.env.accessKey,
    secretKey: process.env.secretKey
}
const minioClient = new Minio.Client(minioConfig);

但是当我创建

minioClient.bucketExists(minioBucketAvatar, function(error, exists) {
    if(error) {
        console.log(error);
    }
    if (exists) {
      return console.log('Bucket exists.', minioBucketAvatar)
    }
    else {
        minioClient.makeBucket(minioBucketAvatar, 'us-east-1', function(err) {
            if (err) return console.log('Error creating bucket.', minioBucketAvatar, err)
            console.log('Bucket created successfully in "us-east-1".', minioBucketAvatar)
        })
    }

});

Dockerfile:

FROM node:10
RUN npm install -g nodemon
WORKDIR /api_kgp
COPY package*.json ./
RUN npm install
COPY . .
CMD node index.js
#Expose port and start application
EXPOSE 5000
CMD [ "npm", "start" ]

当我通过Dockerfile构建项目时,这是错误。按脚本节点运行项目时,一切正常。

Error creating bucket. avatar { Error: connect ETIMEDOUT IP:9000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',

1 个答案:

答案 0 :(得分:0)

请在“ minioConfig”中将“ endPoint ”道具的名称更改为“ endpoint ”。