![urllib.error.HTTPError:HTTP 错误 404:在 Ubuntu 上的 Docker 中未找到](https://linux22.com/image/1178688/urllib.error.HTTPError%EF%BC%9AHTTP%20%E9%94%99%E8%AF%AF%20404%EF%BC%9A%E5%9C%A8%20Ubuntu%20%E4%B8%8A%E7%9A%84%20Docker%20%E4%B8%AD%E6%9C%AA%E6%89%BE%E5%88%B0.png)
我有一个奇怪的问题。Docker 容器应该提供自己的环境,因此如果它们在一个主机平台上工作,那么它也应该在任何其他支持 Docker 的操作系统上工作,对吗?这就是我所理解的 Docker 的主要卖点之一。
我正在通过提供的 Dockerfile 使用基于外部 pytorch 的应用程序。我使用 REST 端点对其进行了扩展,以调用其函数,并正在用它创建新映像。Dockerfile 如下所示:
FROM pytorch/pytorch
ARG gh_username=myUsername
ARG service_home="/home/EasyOCR"
# Configure apt and install packages
RUN apt-get update -y && \
apt-get install -y \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgl1-mesa-dev \
git \
# cleanup
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/li
RUN mkdir "$service_home" \
&& git clone "https://github.com/$gh_username/EasyOCR.git" "$service_home" \
&& cd "$service_home" \
&& git remote add upstream "https://github.com/myUsername/EasyOCR.git" \
&& git pull upstream master
# Build
RUN cd "$service_home" \
python setup.py build_ext --inplace -j 4 \
&& python -m pip install -e .
WORKDIR "$service_home/server"
COPY ./python-server/. "."
RUN pip install -r "requirements.txt"
EXPOSE 5050 # gunicorn is hosted on port 0.0.0.0:5050
ENTRYPOINT ["gunicorn", "--config", "gunicorn_config.py", "wsgi"]
CMD ["--gpus all"]
和docker-compose.yml
:
easy-ocr:
build: .
image: myUsername/easy-ocr
container_name: easy-ocr
ports:
- 5050:5050
在我的 Windows 机器(带有 Docker Desktop WSL2)上运行此映像效果很好。我可以调用端点并获得预期的响应。但是,当我尝试在 Ubuntu 20.04 上运行它时,我在容器中收到以下运行时错误:
easy-ocr | [2020-12-13 18:56:42 +0000] [8] [ERROR] Exception in worker process
easy-ocr | Traceback (most recent call last):
easy-ocr | File "/opt/conda/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
easy-ocr | worker.init_process()
easy-ocr | File "/opt/conda/lib/python3.8/site-packages/gunicorn/workers/base.py", line 119, in init_process
easy-ocr | self.load_wsgi()
easy-ocr | File "/opt/conda/lib/python3.8/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
easy-ocr | self.wsgi = self.app.wsgi()
easy-ocr | File "/opt/conda/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
easy-ocr | self.callable = self.load()
easy-ocr | File "/opt/conda/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
easy-ocr | return self.load_wsgiapp()
easy-ocr | File "/opt/conda/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
easy-ocr | return util.import_app(self.app_uri)
easy-ocr | File "/opt/conda/lib/python3.8/site-packages/gunicorn/util.py", line 358, in import_app
easy-ocr | mod = importlib.import_module(module)
easy-ocr | File "/opt/conda/lib/python3.8/importlib/__init__.py", line 127, in import_module
easy-ocr | return _bootstrap._gcd_import(name[level:], package, level)
easy-ocr | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
easy-ocr | File "<frozen importlib._bootstrap>", line 991, in _find_and_load
easy-ocr | File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
easy-ocr | File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
easy-ocr | File "<frozen importlib._bootstrap_external>", line 783, in exec_module
easy-ocr | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
easy-ocr | File "/home/EasyOCR/server/wsgi.py", line 1, in <module>
easy-ocr | from app import app as application
easy-ocr | File "/home/EasyOCR/server/app.py", line 1, in <module>
easy-ocr | import ocr
easy-ocr | File "/home/EasyOCR/server/ocr.py", line 4, in <module>
easy-ocr | 'ch_sim': easyocr.Reader(['ch_sim']),
easy-ocr | File "/home/EasyOCR/easyocr/easyocr.py", line 82, in __init__
easy-ocr | download_and_unzip(model_url['detector'][0], DETECTOR_FILENAME, self.model_storage_directory)
easy-ocr | File "/home/EasyOCR/easyocr/utils.py", line 540, in download_and_unzip
easy-ocr | urlretrieve(url, zip_path,reporthook=printProgressBar(prefix = 'Progress:', suffix = 'Complete', length = 50))
easy-ocr | File "/opt/conda/lib/python3.8/urllib/request.py", line 247, in urlretrieve
easy-ocr | with contextlib.closing(urlopen(url, data)) as fp:
easy-ocr | File "/opt/conda/lib/python3.8/urllib/request.py", line 222, in urlopen
easy-ocr | return opener.open(url, data, timeout)
easy-ocr | File "/opt/conda/lib/python3.8/urllib/request.py", line 531, in open
easy-ocr | response = meth(req, response)
easy-ocr | File "/opt/conda/lib/python3.8/urllib/request.py", line 640, in http_response
easy-ocr | response = self.parent.error(
easy-ocr | File "/opt/conda/lib/python3.8/urllib/request.py", line 569, in error
easy-ocr | return self._call_chain(*args)
easy-ocr | File "/opt/conda/lib/python3.8/urllib/request.py", line 502, in _call_chain
easy-ocr | result = func(*args)
easy-ocr | File "/opt/conda/lib/python3.8/urllib/request.py", line 649, in http_error_default
easy-ocr | raise HTTPError(req.full_url, code, msg, hdrs, fp)
easy-ocr | urllib.error.HTTPError: HTTP Error 404: Not Found
easy-ocr | [2020-12-13 18:56:42 +0000] [8] [INFO] Worker exiting (pid: 8)
它突然抱怨request.urllib
包,但当我在 Windows 上运行此 Docker 映像时没有问题?我确定 Docker 映像是相同的。Windowsdocker-compose
上的版本是 1.27.4,Ubuntu 上的版本是 1.25.0。我真诚地希望这不是导致此问题的可能原因。
为了进行健全性检查,我决定在 Docker 容器之外运行 python 应用程序并运行,gunicorn --config gunicorn_config.py wsgi
并且它可以正常工作!
我是 Linux 的新手,所以我可能忽略了一些基本知识。这个问题可能是什么原因造成的?
答案1
我找到了答案,但答案非常愚蠢。正在检索的资源不存在...我分叉了一个存储库,代码引用了原始存储库版本中的资产。经过一些测试后,我将分叉存储库中的链接更改为指向我自己的版本,我认为其中包含了所有内容。一切似乎都很好。
然后,我尝试在 Ubuntu 上首次运行该程序,但失败了,因为所需的软件包尚未随 fork 一起复制。有些软件包已复制,有些尚未复制,因此我不确定 fork 的规则是什么。无论如何,我误以为我拥有它们,因为 Windows 一直在“找到”它们。那么,为什么在我删除现有卷和映像的情况下,它在 Windows 上仍然成功?它显然保留了以下行的缓存:
RUN mkdir "$service_home" \
&& git clone "https://github.com/$gh_username/EasyOCR.git" "$service_home" \
&& cd "$service_home" \
&& git remote add upstream "https://github.com/AlexanderTang/EasyOCR.git" \
&& git pull upstream master
尽管我将用户更改为ARG gh_username
我自己的用户,它仍然使用旧值从存储库中提取数据。这意味着它永远不会进入我分叉的存储库,而是进入原始存储库。
触发行上的更改会删除缓存并使 Docker 重新评估该行。当我$gh_username
用自己的用户 ( git clone "https://github.com/myUsername/EasyOCR.git"
) 明确替换时,它 (正确地) 得到了我在 Ubuntu 上遇到的相同错误。