docker运行Python文件

docker pull python:3.5
docker ps  #查看镜像

创建文件pyth.py

print("Hello!")

通过简单的编写Dockerfile实现

编写Dockerfile文件

FROM python:3.5
COPY . /usr/src/mypython
WORKDIR /usr/src/mypython
ENTRYPOINT [ "python" ]
CMD [ "./pyth.py" ]

运行命令:

docker build -t yqq/python .

得出结果:

G:\python\myapp>docker build -t yqq/python .
Sending build context to Docker daemon  3.072kB
Step 1/5 : FROM python:3.5
 ---> 85c44ea592e4
Step 2/5 : COPY . /usr/src/mypython
 ---> Using cache
 ---> 5f97213fb129
Step 3/5 : WORKDIR /usr/src/mypython
 ---> Using cache
 ---> 3d61aeccdc62
Step 4/5 : ENTRYPOINT [ "python" ]
 ---> Using cache
 ---> 1d4f39a84aa5
Step 5/5 : CMD [ "./pyth.py" ]
 ---> Using cache
 ---> a167b4602a06
Successfully built a167b4602a06
Successfully tagged yqq/python:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

再运行命令:

docker run a167b4602a06

得出结果:

G:\python\myapp>docker run a167b4602a06
Hello!
  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值