python - Add pip requirements to docker image in runtime -


i want able add requirements own create docker image. strategy build image dockerfile cmd command execute "pip install -r" command using mounted volume in runtime.

this dockerfile:

from ubuntu:14.04  run apt-get update run apt-get install -y python-pip python-dev build-essential  run pip install --upgrade pip  workdir /root  cmd ["pip install -r /root/sourcecode/requirements.txt"] 

having dockerfile build image:

sudo docker build -t test . 

and try attach new requirements using command:

sudo docker run -v $(pwd)/sourcecode:/root/sourcecode -it test /bin/bash 

my local folder "sourcecode" has inside valid requirements.txt file (it contains 1 line value "gunicorn"). when prompt can see requirements file there, if execute pip freeze command gunicorn package not listed.

why requirements.txt file been attached correctly pip command not working properly?

tldr

pip command isn't running because telling docker run /bin/bash instead.

docker run -v $(pwd)/sourcecode:/root/sourcecode -it test /bin/bash                                                               ^                                                              here 

longer explanation

the default entrypoint container /bin/sh -c. don't override in dockerfile, remains. default cmd instruction nothing. override in dockerfile. when run (ignore volume brevity)

docker run -it test 

what executes inside container is

/bin/sh -c pip install -r /root/sourcecode/requirements.txt 

pretty straight forward, looks run pip when start container.

now let's take @ command used start container (again, ignoring volumes)

docker run -v -it test /bin/bash 

what executes inside container is

/bin/sh -c /bin/bash 

the cmd arguments specified in dockerfile overridden command specify in command line. recall docker run command takes form

docker run [options] image[:tag|@digest] [command] [arg...] 

further reading

  1. this answer has point explanation of cmd , entrypoint instructions do

    the entrypoint specifies command executed when container starts.

    the cmd specifies arguments fed entrypoint.

  2. this blog post on difference between entrypoint , cmd instructions that's worth reading.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -