python-3.x - 安装权限被拒绝的 python 本地包时 Dockerfile 失败
问题描述
我有这个 Dockerfile:
FROM jupyter/scipy-notebook
ADD /dist /our_controller/dist
ADD /wheelhouse /our_controller/wheelhouse
COPY setup.py /our_controller
COPY package.py /our_controller
COPY README.md /our_controller
WORKDIR /app
# add our_controller to python 3.7
RUN python3 -m pip install -e ../our_controller/ --user
docker build -f ./Dockerfile .
我从项目的基本目录中使用此命令。我以前用于python3 setup.py package
创建 ./dist 目录内容,所有依赖项都作为 *.whl 文件存在于 ./wheelhouse 目录中,由 package.py 生成。
我收到此错误:
docker build -f ./Dockerfile .
Sending build context to Docker daemon 810.4MB
Step 1/8 : FROM jupyter/scipy-notebook
---> 19db0c85c56d
Step 2/8 : ADD /dist /our_controller/dist
---> Using cache
---> 018e642c5681
Step 3/8 : ADD /wheelhouse /our_controller/wheelhouse
---> Using cache
---> 94bc3eae623a
Step 4/8 : COPY setup.py /our_controller
---> Using cache
---> 1df4893a77bc
Step 5/8 : COPY package.py /our_controller
---> Using cache
---> 70873a32d702
Step 6/8 : COPY README.md /our_controller
---> Using cache
---> b79ba7f82b77
Step 7/8 : WORKDIR /app
---> Using cache
---> 98d117a270bc
Step 8/8 : RUN python3 -m pip install -e ../our_controller/ --user
---> Running in 7bfa140ca14e
Obtaining file:///our_controller
ERROR: Command errored out with exit status 1:
command: /opt/conda/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/our_controller/setup.py'"'"'; __file__='"'"'/our_controller/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info
cwd: /our_controller/
Complete output (3 lines):
running egg_info
creating ourcontroller.egg-info
error: could not create 'ourcontroller.egg-info': Permission denied
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
The command '/bin/sh -c python3 -m pip install -e ../our_controller/ --user' returned a non-zero code: 1
项目目录中的所有文件都归用户所有,不归根用户所有。我过去创建了几个 Dockerfile,但安装了一个我以前没有尝试过的本地包。我显然错过了一些东西。有人可以指出吗?
解决方案
我也遇到了这个问题。我最终构建了一个轮子,然后在图像中添加并安装了轮子。
当地的
python setup.py bdist_wheel
Dockerfile
FROM jupyter/scipy-notebook
RUN conda install ipdb lxml -y
ADD dist/my_package-0.0.1-py3-none-any.whl my_package-0.0.1-py3-none-any.whl
RUN pip install my_package-0.0.1-py3-none-any.whl
推荐阅读
- python - 如何从边界框获取图像
- python - SciPy.interpolate.griddata() 的快速替代方案
- tensorflow - 用张量流找到交叉熵
- python - 如何在 Python 中使用正确的 X-ticks 将 (x,y) 图叠加到箱线图上?
- javascript - 只允许更改刚刚激活的侧边栏菜单项的图标
- r - 使用knitr在rmarkdown中并排的两个图像?
- r - R中顺序形式的for循环
- python - 使用不同数量的列作为参数的具有动态条件的子集数据框
- python - 数组和从 txt 文件中提取数据时遇到问题。(Python 3.8)
- javascript - 单元测试时如何知道函数中使用的是循环还是双循环?