Home >Operation and Maintenance >Docker >How to run python script on docker

How to run python script on docker

王林
王林Original
2020-03-25 11:18:184491browse

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:

How to run python script on docker

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn