0

I am new to Docker. I know how to build docker images and pip install the required python modules using a requirements.txt. I also know how to add a couple of python apps to the docker image while building it. However, since most of my python scripts are still in the development phase and I update them almost every day, I have put the python scripts in a git repo (that is also added $PATH) instead of building the docker image everyday.

Now, the problem is I would like to run these python $PATH scripts using the python and the modules installed in the docker image and am not sure how to do it. I found a similar previously asked question, but unfortunately, it does not have an answer.

The below is my docker file

FROM ubuntu:18.04
COPY . /app
WORKDIR /app
RUN apt-get install python3 python3-pip
RUN pip3 install -r requirements.txt
ENTRYPOINT bash

Assuming my python script in path is called helloWorld.py and it uses modules mentioned in requirements.txt, how would I run it? Thanks.

Mc Missile
  • 715
  • 11
  • 25
  • did you try `RUN python3 helloWorld.py`? – Leo Sep 21 '20 at 09:05
  • There are two ways of doing this. One is, as mentioned by @Leo, to add the line at the end of your dockerfile. The second way is to [open a terminal window and enter inside the container and run the commands from there](https://stackoverflow.com/questions/26153686/how-do-i-run-a-command-on-an-already-existing-docker-container) – Andi Domi Sep 21 '20 at 09:25
  • 1
    A (non-Docker) Python virtual environment is a better match for something you're actively working on. If you want to run it in Docker, you need to delete that `ENTRYPOINT` line, and then you can `docker run --rm image-name python3 script.py` to run a single script in a container. – David Maze Sep 21 '20 at 11:46

0 Answers0