How to run my python script on docker?

前端 未结 6 406
小蘑菇
小蘑菇 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条回答
  •  执念已碎
    2020-12-14 08:02

    its very simple

    1- go to your Python script directory and create a file with this title without any extension

    Dockerfile

    2-now open the docker file and write your script name instead of sci.py

    ( content of Dockerfile )

    FROM python:slim #i choice slim version you can choose another tag for example python:3
    
    WORKDIR /usr/local/bin
    
    COPY sci.py .    #replace you scrip name with sci.py
    
    CMD [ "python", "sci.py" ] #replace you scrip name with sci.py
    

    save it and now you should create image file from this dockerfile and script py

    and next run it

    3-in path address folder write CMD and press Enter key :

    4-When the cmd window opens for you, type in it :

    docker build -t my-python-app .  #this create image in docker by this title my-python-app
    

    5- and findly run image:

    docker run -it --rm --name my-running-app my-python-app 
    

提交回复
热议问题