简体   繁体   English

从 Docker 运行 python 脚本

[英]Run python script from Docker

Trying to run test Python script from Docker using Bash.尝试使用 Bash 从 Docker 运行测试 Python 脚本。 Win10 OS. Win10 操作系统。 I have a file print.py in the directory C:/Py/test我在目录C:/Py/test中有一个文件print.py

  1. run this $ cd C:/Py/test运行这个$ cd C:/Py/test
  2. run this $ docker run --volume $(pwd):/home/${USER} python:3.7 python /home/${USER}/print.py运行这个$ docker run --volume $(pwd):/home/${USER} python:3.7 python /home/${USER}/print.py

Got this error: python: can't open file 'C:/Program Files/Git/home/print.py': [Errno 2] No such file or directory收到此错误: python: can't open file 'C:/Program Files/Git/home/print.py': [Errno 2] No such file or directory

Why is this file trying to be found in the C:/Program Files/Git/home/ directory instead of C:\Py\test ?为什么试图在C:/Program Files/Git/home/目录而不是C:\Py\test目录中找到此文件?

$ python 'print.py' is working $ python 'print.py'正在工作

在此处输入图像描述

Git bash prepended its installation path, try these two methods: Git bash 前置其安装路径,试试这两种方法:

  1. Use: //home/${USER}/print.py使用://home/${USER}/print.py

  2. Run with: MSYS_NO_PATHCONV=1 docker run...运行: MSYS_NO_PATHCONV=1 docker 运行...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM