Search code examples
dockerdockerfiledocker-volume

Pandas not found in Docker Run Command [attaching volumne]


When I build my docker image and run it using the following commands:

docker build -t iter1 .

docker run -it --rm --name iter1_run iter1

My application runs just fine. However when I try to attach a volume and execute the following command:

docker run -it --rm --name iter_run -v /Users/xxxx/Desktop/Docker_Builds/SingleDocker/xxxxxx:/usr/src/oce -w /usr/src/oce python:3 python oce_test.py

The file oce_test.py cant find Pandas.

Traceback (most recent call last):
  File "oce_test.py", line 1, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

The content of my Dockerfile is as follows:

# Docker image
FROM python:3

# Copy requirements
COPY requirements.txt /

# Install Requirements
RUN pip install -r /requirements.txt

# Copy scripts needed for execution
COPY ./xxxx /usr/src/oce

# Establish a working directory
WORKDIR /usr/src/oce

# Execute required script
CMD ["python", "oce_test.py"]

The content of my requirements.txt is as follows:

numpy==1.18.1
pandas==1.0.1
matplotlib==3.1.3
scipy==1.4.1
Python-dateutil==2.8.1

Solution

  • David Maze answered this:

    Your docker run command is running a plain python:3 image with no additional packages installed. If you want to use the image from your Dockerfile, but overwriting the application code in the image with arbitrary content from your host, use your image name iter1 instead. (You don't need to repeat the image's WORKDIR or CMD as docker run options.)