Error: can't chdir to 'app' when using docker start container
Error: can't chdir to 'app' when using docker start container
我已经构建了一个简单的 Flask 应用程序,我正尝试在 Docker 上 运行 它,但在启动容器时出现此错误:Error: can't chdir to 'app'
应用程序 运行 当我从 cmd 启动它时很好,但是当我尝试为我创建的图像启动 docker 容器时,它给出了上述错误。
这是 Docker 文件:
FROM python:3.6.12-alpine
COPY requirements.txt /
RUN pip3 install -r /requirements.txt
COPY . /app
WORKDIR /app
RUN chmod 777 /app
ENTRYPOINT ["./gunicorn.sh"]
我正在尝试 运行 它与 gunicorn 网络服务器。在我的需求文件中,我有 flask 和 gunicorn,对于 python 应用程序,我只有一个文件,代码如下:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
我正在执行以下步骤来构建映像和容器:
- docker build -t flask .
- docker 运行 -d -p 80:80 烧瓶
- docker start -ai (容器的id)
- 我收到我提到的错误 -> 错误:无法 chdir 到 'app'
有人可以告诉我为什么容器没有启动并且给我这个错误吗?谢谢
您不需要 change directory。 --chdir app
不需要参数。因为您已经在 /app
目录中(您还记得 Dockerfile
中的 WORKDIR /app
吗?)。
通过其他方式,您可以使用 --chdir /app
或 --chdir .
将目录(如果默认设置不起作用)更改为当前工作目录
改成
#!/bin/sh
gunicorn app:app -w 2 --threads 2 -b 0.0.0.0:80
# OR
gunicorn --chdir /app app:app -w 2 --threads 2 -b 0.0.0.0:80
# OR
gunicorn --chdir . app:app -w 2 --threads 2 -b 0.0.0.0:80
RUN chmod 777 /app
也不需要
我已经构建了一个简单的 Flask 应用程序,我正尝试在 Docker 上 运行 它,但在启动容器时出现此错误:Error: can't chdir to 'app'
应用程序 运行 当我从 cmd 启动它时很好,但是当我尝试为我创建的图像启动 docker 容器时,它给出了上述错误。
这是 Docker 文件:
FROM python:3.6.12-alpine
COPY requirements.txt /
RUN pip3 install -r /requirements.txt
COPY . /app
WORKDIR /app
RUN chmod 777 /app
ENTRYPOINT ["./gunicorn.sh"]
我正在尝试 运行 它与 gunicorn 网络服务器。在我的需求文件中,我有 flask 和 gunicorn,对于 python 应用程序,我只有一个文件,代码如下:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
我正在执行以下步骤来构建映像和容器:
- docker build -t flask .
- docker 运行 -d -p 80:80 烧瓶
- docker start -ai (容器的id)
- 我收到我提到的错误 -> 错误:无法 chdir 到 'app'
有人可以告诉我为什么容器没有启动并且给我这个错误吗?谢谢
您不需要 change directory。 --chdir app
不需要参数。因为您已经在 /app
目录中(您还记得 Dockerfile
中的 WORKDIR /app
吗?)。
通过其他方式,您可以使用 --chdir /app
或 --chdir .
改成
#!/bin/sh
gunicorn app:app -w 2 --threads 2 -b 0.0.0.0:80
# OR
gunicorn --chdir /app app:app -w 2 --threads 2 -b 0.0.0.0:80
# OR
gunicorn --chdir . app:app -w 2 --threads 2 -b 0.0.0.0:80
RUN chmod 777 /app
也不需要