在尝试 Docker 教程时https://prakhar.me/docker-curriculum/#dockerrun 运行 root@ip-172-31-22-20:~/docker-curriculum# docker build -t ashishkarpe/foodtrucks-web 时出现错误。
root@ip-172-31-22-20:~/docker-curriculum# docker build -t ashishkarpe/foodtrucks-web .
Sending build context to Docker daemon 5.32 MB
Step 1 : FROM ubuntu:14.04
---> 3f755ca42730
Step 2 : MAINTAINER Prakhar Srivastav [email protected]
---> Using cache
---> ca0cf0254114
Step 3 : RUN apt-get -yqq update
---> Using cache
---> 4952fb95a34d
Step 4 : RUN apt-get -yqq install python-pip python-dev
---> Using cache
---> 73bd849c6164
Step 5 : RUN apt-get -yqq install nodejs npm
---> Using cache
---> c48d602eccda
Step 6 : RUN ln -s /usr/bin/nodejs /usr/bin/node
---> Using cache
---> 221206c99a7f
Step 7 : ADD flask-app /opt/flask-app
---> Using cache
---> 7ddfac0cdf0e
Step 8 : WORKDIR /opt/flask-app
---> Using cache
---> 451217e08677
Step 9 : RUN npm install
---> Running in 547c36e97297
npm ERR! install Couldn't read dependencies
npm ERR! Error: ENOENT, open '/opt/flask-app/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]
npm ERR! System Linux 3.13.0-92-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! cwd /opt/flask-app
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! path /opt/flask-app/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /opt/flask-app/npm-debug.log
npm ERR! not ok code 0
我的Docker文件:
# cat Dockerfile
# start from base
FROM ubuntu:14.04
MAINTAINER Prakhar Srivastav <[email protected]>
# install system-wide deps for python and node
RUN apt-get -yqq update
RUN apt-get -yqq install python-pip python-dev
RUN apt-get -yqq install nodejs npm
RUN ln -s /usr/bin/nodejs /usr/bin/node
# copy our application code
ADD flask-app /opt/flask-app
WORKDIR /opt/flask-app
# fetch app specific deps
RUN npm install
RUN npm run build
RUN pip install -r requirements.txt
# expose port
EXPOSE 5000
答案1
这是由于 Ubuntu 14.04 的 npm 过期而引发的错误,为了解决快速修复添加行
ADD package.json /opt/flask-app
RUN npm config set strict-ssl false
在这些行之后
# copy our application code
ADD flask-app /opt/flask-app
WORKDIR /opt/flask-app