How to install packages to docker's python?
For example, I need
lmxl. Inside django application in docker I run
pip install lxml and terminal responses that requirement is already satisfied (because it’s installed in OS X python 2.7 packages), but in fact it’s not installed in docker’s python packages.
So, how to apply
pip install something to docker?
3 Solutions collect form web for “How to install packages to docker's python?”
The correct way is to update the requirements.txt file of your project.
# requirements.txt # .. other requirements lxml
add the lxml dependencies to your Dockerfile after (RUN apt-get update …..)
RUN apt-get install -y python-dev libxml2-dev libxslt1-dev zlib1g-dev
now build and run. Using either
docker-compose build docker-compose up
docker-compose up --build
You would use Docker’s
docker-compose run --rm --service-ports web bash command. That will bring you to the command line of the container. Once there, you can run
pip install lxml. After installation, just type
exit, and you will exit the container used to the
web container and remove it.
Here’s the article on Docker run for reference: https://docs.docker.com/compose/reference/run/
There are many ways to install packages in docker but i prefer is to use docker file
check out these links it might help you.