我尝试为Node应用构建镜像,但当我执行Docker构建时,出现了一个错误,提示我先运行npm install。
npm ERR! network timeout at: https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz
以下是Docker文件的内容:
FROM node:13
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
跟随我的 package.json
{
"name": "backend",
"version": "1.0.0",
"description": "",
"private": true,
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Bruno Cassiamani",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"config": "^3.3.1",
"consign": "^0.1.6",
"cors": "^2.8.5",
"express": "^4.17.1",
"request": "^2.88.2",
"xml2js": "^0.4.23"
}
}
操作系统版本:CentOS Linux release 8.1.1911 (Core)
Docker 版本:Docker version 19.03.8,build afacb8b