Docker CMD 未执行,程序未执行 运行
Docker CMD not executing, program not running
所以我有一个 python 项目,我有一个 Dockerfile,但是问题出在我构建 docker 图像然后 运行 它时我没有'看到代码的结果我会看到如果我只是 运行 它通常在 pycharm 或控制台上,有人知道为什么会这样吗?太奇怪了。
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
COPY . /app
RUN pip3 install -r requirements.txt
CMD ["python3","main.py"]
requirements.txt 文件是我存储程序运行所需的所有软件包的地方。
您将应用程序复制到错误的路径。
因为你使用WORKDIR
你需要知道(从正式的site):
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile
这意味着您的 COPY . /app
将您的应用程序复制到 /app/app
,但是当您编写 CMD ["python3","main.py"]
时,此命令将在 /app
中执行。我相信 main.py
文件不存在,但在 /app/app
.
中
要修复它,您需要将 COPY . /app
更改为 COPY . .
所以我有一个 python 项目,我有一个 Dockerfile,但是问题出在我构建 docker 图像然后 运行 它时我没有'看到代码的结果我会看到如果我只是 运行 它通常在 pycharm 或控制台上,有人知道为什么会这样吗?太奇怪了。
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
COPY . /app
RUN pip3 install -r requirements.txt
CMD ["python3","main.py"]
requirements.txt 文件是我存储程序运行所需的所有软件包的地方。
您将应用程序复制到错误的路径。
因为你使用WORKDIR
你需要知道(从正式的site):
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile
这意味着您的 COPY . /app
将您的应用程序复制到 /app/app
,但是当您编写 CMD ["python3","main.py"]
时,此命令将在 /app
中执行。我相信 main.py
文件不存在,但在 /app/app
.
要修复它,您需要将 COPY . /app
更改为 COPY . .