Docker file to run Python with Pandas

Viewed 10793

I have created the following Dockerfile

FROM python
COPY . /home
CMD pip install pandas
CMD mkdir /home/report
CMD mkdir /home/data
CMD python /home/hello.py

where hello.py is the simple Python script

name = input('What is your Name? ')
print('Nice to meet you', name)

from pandas import read_csv
mydf = read_csv('mycsv.csv')
print(mydf.head())

I then build the Docker image with docker build -t myexample . and run it with docker run -it myexample bash so as to interact with it via the shell. The building goes fine and upon running it I presented with the shell prompt, but then:

  • No directories report or data have been created under /home.
  • The last command python /home/hello.py does not execute on its own. I have to type it myself to get the script to run.
  • Once I type python /home/hello.py, the first two lines that greet and prompt for my name are executed properly, but then an error says that pandas is unknown.
  • It is not until I install pandas manually that the whole script runs correctly.

So, in summary, it seems that none of the CMD statements were taken into account. What am I doing wrong?

2 Answers
Related