fightstarr20
fightstarr20

Reputation: 12598

Docker - Add Python and Dependencies to Apache

I have a python script that I am trying to create a docker container for. I am new to docker so please excuse if this is real simple!

If I am setting up my existing python script on a new system I always run the following to install dependencies....

pip install numpy opencv-python dlib imutils

I have a basic Dockerfile that loads PHP with apache like this...

FROM php:7.0-apache
COPY src/ /var/www/html
EXPOSE 80

Is there a way I can add Python into the stack and install those dependencies? Or have I got Docker totally wrong?

Upvotes: 1

Views: 2296

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133508

If I understood correctly on very first point, you need to get some packages from Python then try following once(as an example, I am importing Python's 2.7 version's image here).

FROM python2.7-slim

Then for multiple packages installations you could create a file named requirements.txt(which will have all packages details in it) and then could run following command too in it.

cat requirements.txt
numpy
opencv-python
dlib
imutils

pip install -r requirements.txt


If I am setting up my existing python script on a new system I always run the following to install dependencies....

Little explanation on Concept of Docker: So concept of Docker is NOT TO INSTALL dependencies on any machines and make our codes to run on any machine without putting additional stuff to install our code's dependencies etc. Basically our Dockerize solution should be capable to handle any system. Here is what the steps would be:

1- Create your code in Python(here taking example of it). 2- Now place it in docker's directory. 3- MOST important step create a file named Dockerfile in docker's directory. 4- Now mention all sequence of commands in it, following is an example of Dockerfile`:

FROM python2.7-slim
DIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["python","your_python_code_file"]

So here you could see whenever we build our image(combination of our code and Dockerfile) we need NOT TO install anything in our actual server/machine this is benefit of Docker our image SHOULD BE dependency free. Once we build our image and post it to repository same image could be used by any other person on any other machine too.

Upvotes: 1

Related Questions