How to install packages to docker's python?

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.

  • Different result using docker-compose vs docker run
  • Docker commit does't save changes
  • Docker container doesn't expose ports when --net=host is mentioned in the docker run command
  • docker container ssl certificates
  • Fork docker repository
  • Docker failed to fetch http://deb.debian.org/debian/dists/jessie/InRelease
  • So, how to apply pip install something to docker?

  • Save export images from one server to another
  • Node cli program not working in windows machine
  • Httplib2 exception raised when calling Twilio from python
  • Spring security default login redirecting client to docker gateway IP behind zuul proxy
  • Why “git clone” is trying to use https
  • Docker Swarm CD/CI (Jenkins, 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
    

    or

    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/

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.