1

I'm building a docker image that suppose to run a python script that depends on some packages (numpy) I install during the build. During build everything appears to be installed correctly but when I run the container it behaves like those packages were never installed. What seems to be the problem with my code ?

My docker file looks like this :

FROM myimage as intermediate

WORKDIR ./app

COPY ./mathServer ./mathServer/

RUN apt-get update

RUN apt-get install sudo 

RUN sudo apt-get install python3-pip -y

RUN sudo pip3 install numpy 

RUN sudo pip3 install httpserver 

RUN pip3 list

WORKDIR ./app

COPY --from=intermediate ./app/* ./

CMD ["sh","-c","python3 mathServer/mathServer.py"]

I would expect docker run myimage to run mathServer.py successfully but instead it complains about numpy package. "importError: No module named 'numpy''" Also if I replace command "python3 mathServer/mathServer.py" with command "pip3 list" pip3 command does not exist. Somehow the packages installed during build are not available when I'm actually running the container.

1
  • this may helps Commented Sep 10, 2019 at 11:56

1 Answer 1

1

Please check your docker build log. Numpy requests c compiler and fortran compiler to build and install. It is likely the installation was not successful.

Consider try pre-build dockers such as https://hub.docker.com/r/continuumio/miniconda/, and add numpy via RUN <PATH_TO>/conda install numpy -y

Or https://hub.docker.com/r/continuumio/anaconda3 that already have numpyinstalled.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply. Installation appears to be fine along with other packages there is no error during build. Here is the result of the installed packages pip3 list : httpserver (1.1.0) keyrings.alt (1.3) numpy (1.17.2) pip (9.0.1) However "pip3 list" does not work when I'm runing the container with CMD [..]. I think this is the same reason why numpy isn't visible either.
So it was a mistake in my docker file , the instructions I had at the end WORKDIR ./app COPY --from=intermediate ./app/* ./ override the numpy instalation So you were right :) by the time I was running the container numpy was not installed
ha that's easy, nonetheless, the conda/miniconda based dockers are worth trying. More consistent at least.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.