[英]Docker container runs locally but fails on Cloud Run
I moved project from PIP to Poetry and my Docker container failed to run on Google Cloud Run.我将项目从 PIP 移至 Poetry,而我的 Docker 容器无法在 Google Cloud Run 上运行。
Last string in Docker: Docker 中的最后一个字符串:
CMD ["poetry", "run", "uwsgi", "--http-socket", "0.0.0.0:80", "--wsgi-file", "/server/app/main.py", "--callable", "app", "-b 65535"]
It's works locally, it's works on other laptop, it's works in Cloud Run Emulator, but fails when I try to run it on Cloud Run.它在本地工作,在其他笔记本电脑上工作,在 Cloud Run Emulator 中工作,但是当我尝试在 Cloud Run 上运行它时失败。
Here is a Cloud Run log:这是 Cloud Run 日志:
Creating virtualenv my-project-xTUGyw3C-py3.8 in /home/.cache/pypoetry/virtualenvs
FileNotFoundError
[Errno 2] No such file or directory: b'/bin/uwsgi'
at /usr/local/lib/python3.8/os.py:601 in _execvpe
597│ path_list = map(fsencode, path_list)
598│ for dir in path_list:
599│ fullname = path.join(dir, file)
600│ try:
→ 601│ exec_func(fullname, *argrest)
602│ except (FileNotFoundError, NotADirectoryError) as e:
603│ last_exc = e
604│ except OSError as e:
605│ last_exc = e
Container called exit(1).
It's have correct port set.它有正确的端口设置。 It's doesn't use any environment variables.它不使用任何环境变量。 I don't use volumes, files passed to Docker through COPY.我不使用通过 COPY 传递给 Docker 的卷、文件。
Logs says that application can't find uwsgi file.日志显示应用程序找不到 uwsgi 文件。 That file doesn't exists in local version too, but it's works without any errors.该文件在本地版本中也不存在,但可以正常运行。
How that even possible that a docker container behaves differently? docker 容器的行为有何不同?
UPD: My Docker file UPD:我的 Docker 文件
FROM python:3.8
WORKDIR server
ENV PYTHONPATH $PYTHONPATH:/server
RUN pip install poetry==1.1.11
COPY poetry.lock /server
COPY pyproject.toml /server
RUN poetry install
EXPOSE 80
COPY /data /server/data
COPY /test /server/test
COPY /app /server/app
CMD ["poetry", "run", "uwsgi", "--http-socket", "0.0.0.0:80", "--wsgi-file", "/server/app/main.py", "--callable", "app", "-b 65535"]
adding HOME=/root
to the CMD, fixed the problem for me.将HOME=/root
添加到 CMD,为我解决了问题。
CMD HOME=/root poetry run python main.py
Apparently home is not set correctly and this is a known issue显然 home 设置不正确,这是一个已知问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.