我现在一直在学习docker,我制作了一个像这样的docker文件。
FROM node:10
# Create app directory
WORKDIR /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 /app/
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
ADD ./* /app/
EXPOSE 8080
CMD [ "npm", "start" ]
我的文件目录如下:
我的服务器在我的本地计算机上运行良好,但是,在使用docker容器运行时,抛出了错误。 错误是:
有人可以帮我吗?
答案 0 :(得分:1)
将Dockerfile
更新为以下内容并尝试:
FROM node:10
# Create app directory
WORKDIR /app/
# RUN apt-get update && apt-get install -y --no-install-recommends nano
# 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 install --only=production
COPY . .
CMD ["node", "server.js"]
EXPOSE 8080
设置WORKDIR to /app/
时,当前目录将更新。因此,在复制过程中无需提及/app
。
答案 1 :(得分:1)