How to run my python script on docker?

前端 未结 6 407
小蘑菇
小蘑菇 2020-12-14 07:10

I am trying to run my python script on docker. I tried different ways to do it but not able to run it on docker. My python script is given below:

import os

         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 07:59

    You need to create a dockerfile in the directory your script is in.

    You can take this template:

    FROM python:latest
    
    COPY scriptname.py /usr/local/share/
    
    CMD ["scriptname.py", "-flag"]
    

    Then simply execute docker build -t pulkit/scriptname:1.0 . and your image should be created.

    Your image should be visible under docker images. If you want to execute it on your local computer, use docker run.

    If you want it to upload to the DockerHub, you need to log into the DockerHub with docker login, then upload the image with docker push.

提交回复
热议问题