Docker Toolbox 錯誤“無法開啟檔案”

Docker Toolbox 錯誤“無法開啟檔案”

我一直在努力使用 Docker Toolbox 在 Windows 10 Home 上啟動並執行 Docker 映像。這是我在 Kitematic 中看到的錯誤:

python: can't open file 'src/__main__.py': [Errno 2]   
No such file or directory

這個失敗的 Python 指令是「notes」Docker 容器的入口點。

Docker/up.sh 之後,流程完成且沒有任何錯誤。

Successfully built f59c275721cf
Successfully tagged docker_mysql:latest
Creating mysql ... done
Creating notes ... done

此外,這是一個小組項目,Mac 上的其他使用者無法重複此錯誤。將 Dockerfile 更新為以下內容並執行後:

Successfully built 42a95cd419f2
Successfully tagged docker_mysql:latest
Creating mysql ... done
Creating notes ... done

User@DESKTOP-EBUI9GE MINGW64 /c/users/user/Desktop/6440/Procedure-Notes-Application (master)
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
68f60fdba6f5        docker_mysql        "docker-entrypoint.s…"   15 seconds ago      Up 9 seconds        0.0.0.0:23306->3306/tcp   mysql

User@DESKTOP-EBUI9GE MINGW64 /c/users/user/Desktop/6440/Procedure-Notes-Application (master)
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                     NAMES
e7fbd5b73189        docker_notes        "python /app/src/__m…"   23 seconds ago      Exited (2) 17 seconds ago                             notes
68f60fdba6f5        docker_mysql        "docker-entrypoint.s…"   23 seconds ago      Up 17 seconds               0.0.0.0:23306->3306/tcp   mysql

更新後的 Dockerfile:

### Use an official Python runtime as a parent image 
FROM python:2.7-slim

### set working directory to the code location
WORKDIR /app

### copy the code base over (redone by the compose file)
COPY . .

### Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

### Make port available to the world outside this container
EXPOSE 5000

### start the application
CMD ["python", "/app/src/__main__.py"]

我現在收到另一個錯誤:

 * Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "/app/src/__main__.py", line 57, in <module>
    app.run(debug=True, host='0.0.0.0')
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 943, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/serving.py", line 988, in run_simple
    run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
    sys.exit(reloader.restart_with_reloader())
  File "/usr/local/lib/python2.7/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
    exit_code = subprocess.call(args, env=new_environ, close_fds=False)
  File "/usr/local/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/local/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/local/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error

答案1

我的第一句話是:

您不需要 mkdir,因為 WORKDIR 會創建它。最好使用絕對引用,例如WORKDIR /appCMD ["python", "/app/src/__main__.py"]

Python 腳本現在啟動並停止錯誤:

  File "/usr/local/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception

這通常是 Python 腳本中的錯誤。帖子中描述了一種可能性 python subprocess.call() 未如預期般運作:

預設subprocess.call不使用 shell 來執行我們的命令,因此您無法使用 shell 命令,例如cd.

若要使用 shell 執行命令,請使用shell=True參數。在這種情況下,建議將命令作為單一字串而不是列表傳遞。由於它是由 shell 運行的,因此您~/也可以在路徑中使用:

subprocess.call("(cd ~/catkin_ws/src && catkin_make)", shell=True)

相關內容