I downloaded a python script and a docker image containing commands to install all the dependencies. How can I run the python script using the docker image?
I downloaded a python script and a docker image containing commands to install all the dependencies. How can I run the python script using the docker image?
4
Answers
Answer
First, Copy your python script and other required files to your docker container.
Second, open the container cli using docker desktop and run your python script.
Copy python file in Docker image then execute –
Or you can also build the DockerFile by using the RUN python PATH-OF-SCRIPT-IN-IMAGE/script.py inside DockerFile.
How to copy container to host
How to copy host to the container
Run in interactive mode:
or if you want host and port to be specified:
The best way, I think, is to make your own image that contains the dependencies and the script.
When you say you’ve been given an image, I’m guessing that you’ve been given a Dockerfile, since you talk about it containing commands.
Place the Dockerfile and the script in the same directory. Add the following lines to the bottom of the Dockerfile.
Replace
my-script.py
with the name of the script.Then build and run it with these commands