Home >Operation and Maintenance >Docker >How to run python script on docker
First create a specific project directory for the docker image. For example:
mkdir /home/pi/Desktop/teasr/capturing
Copy the dockerfile and script there and change the current context to this directory
cp /home/pi/Desktop/teasr/capturing.py /home/pi/Desktop/teasr/dockerfile /home/pi/Desktop/teasr/capturing/ cd /home/pi/Desktop/teasr/capturing
This is best practice because the first thing docker-engine does when building is read the entire current context.
Next we will look at your dockerfile. It should now look like this:
The next thing you need to do is build it with a smart name, dots are generally discouraged.
docker build -t pulkit/capturing:1.0 .
The next step is to run the image as you did.
docker run -ti --name capturing pulkit/capturing:1.0
The script now executes inside the container and may exit when completed.
Note: The first line in the script needs to be #! /usr/bin/envpython.
Recommended tutorial: docker tutorial
The above is the detailed content of How to run python script on docker. For more information, please follow other related articles on the PHP Chinese website!