How to check whether python package is installed or not in Docker?

28,993

I figured out.

docker exec <container ID> pip list
Share:
28,993
Bruce Yong Li
Author by

Bruce Yong Li

I'm a new soul. I came to this strange world. Hoping I could learn a bit about how to give and take. But since I came here, felt the joy and the fear, finding myself making every possible mistake.

Updated on July 18, 2022

Comments

  • Bruce Yong Li
    Bruce Yong Li almost 2 years

    I used Dockerfile successfully built a container. However, my code doesn't work in the container. It does work if I install all the packages manually. I'm assuming I messed up something that cause docker didn't install the packages properly. So, I want to check whether python package is installed or not in Docker container. What is the best way to check it?

    The Dockerfile I used:

    # Update the sources list
    RUN sudo apt-get update
    
    # Install basic applications
    RUN sudo apt-get install -y tar git curl nano wget dialog net-tools build-essential
    
    # First install ZeroMQ
    RUN sudo apt-get install -y libzmq-dev
    
    # Install libevent
    RUN sudo apt-get install -y libevent-dev
    
    # Install Python and Basic Python Tools
    RUN sudo apt-get install -y python python-dev python-setuptools
    RUN sudo apt-get install -y python-pip 
    
    # Add the current directory to the container
    ADD . /root/code
    
    # Get pip to download and install requirements:
    RUN sudo pip install -r /root/code/requirements.txt
    
    # Expose ports
    EXPOSE 80 4242
    
    # Define working directory.
    WORKDIR /root/code
    
    # Start the tcp server.
    CMD python app.py
    

    The requirements.txt I used:

    gevent==1.0.1
    greenlet==0.4.5
    msgpack-python==0.4.2
    pyzmq==13.1.0
    wsgiref==0.1.2
    zerorpc==0.4.4
    
  • Prasad Shinde
    Prasad Shinde over 5 years
    are you sure all the modules inside requirements.txt are get installed/accessible in docker container?
  • Bruce Yong Li
    Bruce Yong Li over 5 years
    This command has nothing to do with requirements.txt. docker exec <container ID> pip list is basically run pip list inside of the container to get all packages installed for the default python of the container. So, to make sure you have packages in your requirements.txt installed, you may try docker exec <container ID> cd <your python project folder, where you store requirements.txt> && pip install -r requirements.txt
  • Morteza Mashayekhi
    Morteza Mashayekhi over 5 years
    for me this one worked: docker run <container ID> pip list.
  • vogash
    vogash almost 5 years
    The question is how can you list all packages inside docker image without running container
  • Diego Castanho
    Diego Castanho over 2 years
    For me to update the version to pymongo 4.0, so I switched to version 3.12.1 and it worked. Thank you very much.