0

I am trying to download the Pika package using Pip3 inside of a Dockerfile/container. My current Dockerfile looks like this:

FROM rabbitmq

#install Python
RUN apt-get update &&\
    apt-get install -y \
    python3-pip

#Create new user
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user

#Install Pika
RUN pip3 install pika

RUN mkdir videos

COPY . .

CMD ["python3", "ffmpeg.py"]

The output I get claims that it all works and everything is installed successfully. However the container exits immediately due to the error:

Traceback (most recent call last):
File "ffmpeg.py", line 1, in <module>
import pika, sys, os
ModuleNotFoundError: No module named 'pika'

If I SSH into the container and download Pika manually using:

pip3 install pika

And then run the python file, everything works. But for some reason the Dockerfile can't install it with the exact same command.

So far I've tried pretty much every solution on this page

I'm running Ubuntu version 20.04.1 and Docker version 20.10.2.

Anything else I can try?

Brady Harper
  • 235
  • 1
  • 3
  • 17

1 Answers1

0

So I think I found a solution. I changed my Dockerfile to have my Pika installation above the creation of a new user. So it now looks like this:

FROM rabbitmq

#install Python
RUN apt-get update &&\
    apt-get install -y \
    python3-pip

#Install Pika
RUN python3 -m pip install pika

#Create new user
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user

RUN mkdir videos

COPY . .

CMD ["python3", "ffmpeg.py"]

This has fixed my issue of Pika not being recognised but now when building the image I get this:

The directory '/var/lib/rabbitmq/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

The image still builds and the file now runs, so not sure what kind of effect the new error has.

Brady Harper
  • 235
  • 1
  • 3
  • 17