user2574872 user2574872 - 4 months ago 10
Python Question

"python setup.py install" does not work from Dockerfile but i can go in the container and do the same..any pointers?

I am getting this error while doing "sudo docker build ."

> (3:58:02 PM) njain: tep 28 : RUN python /tmp/setup.py install &&
> python /tmp/buzz/scripts/setuprabbit.py ---> Running in e7afcbda3c75
> Traceback (most recent call last): File "/tmp/setup.py", line 7, in
> <module>
> long_description=open('README.md', 'r').read(), IOError: [Errno 2] No such file or directory: 'README.md' 2014/10/15 15:40:14 The command
> [/bin/sh -c python /tmp/setup.py install && python
> /tmp/buzz/scripts/setuprabbit.py] returned a non-zero code


my Dockerfile looks like this :-

ADD buzz /tmp/
# DOCKER-VERSION 0.3.4
#bunch of installs
RUN cd /tmp/
RUN python /tmp/setup.py install && python /tmp/buzz/scripts/setuprabbit.py


when i go in the container (interactive shell and CD to /tmp/ i am able to to do python setup.py install without any issue)

Answer

each step in a docker file:

  • creates a container
  • changes it in some way
  • commits the result (usually) to create a new image
  • removes the container.
  • use the new image in the next step

So your docker file says:

ADD buzz /tmp/            # change the container to have this new file
# DOCKER-VERSION 0.3.4
#bunch of installs
RUN cd /tmp/              # don't change the container at all and then save the results
RUN  python /tmp/setup.py install &&  python /tmp/buzz/scripts/setuprabbit.py  ## do the install

so the cd command on the second to last line does nothing and does not affect lines after it. This is an unfortunate side effect of making docker files look too much like shell scripts which they are not. Instead put the cd command on the same line that needs to use it so that it's effects will carry forward along that line though not to other RUN commands in the same Dockerfile

RUN cd /tmp/ && python /tmp/setup.py install &&  python /tmp/buzz/scripts/setuprabbit.py