Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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.

like image 416
user2574872 Avatar asked Oct 15 '14 21:10

user2574872


2 Answers

Arthur's answer correctly identifies the cause of your problem, and provides a valid solution.

However, Docker's "Best Practices for Writing Dockerfiles" recommends against using the pattern he suggested (i.e. RUN cd /some/path && do-some-command), and instead recommends using the WORKDIR instruction (which is intended to address this exact use case).

WORKDIR basically works exactly how you intended your cd command to work: it changes working directory, with the new working directory being retained for later instructions in the Dockerfile.

In your case, the resulting Dockerfile would look like this:

ADD buzz /tmp/
# DOCKER-VERSION 0.3.4
#bunch of installs
WORKDIR /tmp/
RUN  python /tmp/setup.py install &&  python /tmp/buzz/scripts/setuprabbit.py
like image 129
Mac Avatar answered Sep 20 '22 15:09

Mac


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
like image 32
Arthur Ulfeldt Avatar answered Sep 19 '22 15:09

Arthur Ulfeldt