Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile fails when installing a python local package with permission denied

I have this 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

I use this command docker build -f ./Dockerfile . from the base directory of my project. I had previously used python3 setup.py package to create the ./dist directory content and all dependencies are present in the ./wheelhouse directory as *.whl files, generated by the package.py.

I get this error:

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

All files in the project directory are owned by the user, none by root. I have created several Dockerfile in the past but installing a local package I have not attempted previously. I have clearly missed something. Can someone point it out?

like image 458
Olddave Avatar asked Feb 25 '20 15:02

Olddave


1 Answers

I hit this issue as well. I wound up building a wheel and then adding and installing the wheel in the image.

local

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

like image 165
Joshua Cook Avatar answered Nov 02 '22 23:11

Joshua Cook