[英]Docker containers randomly shutting down
所以我有这个系统,我有 3 个 docker 容器同时运行来托管我的 API,一个用于 traefik,另外两个用于不同的 API(使用 FastAPI 以 python 编写)。 它工作了一段时间,但现在所有docker 容器似乎在几个小时后随机关闭。
这是所有错误消息output:
Exception in thread Thread-5:
Traceback (most recent call last):
File "urllib3/connectionpool.py", line 677, in urlopen
File "urllib3/connectionpool.py", line 392, in _make_request
File "http/client.py", line 1277, in request
File "http/client.py", line 1323, in _send_request
File "http/client.py", line 1272, in endheaders
File "http/client.py", line 1032, in _send_output
File "http/client.py", line 972, in send
File "docker/transport/unixconn.py", line 43, in connect
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "requests/adapters.py", line 449, in send
File "urllib3/connectionpool.py", line 727, in urlopen
File "urllib3/util/retry.py", line 410, in increment
File "urllib3/packages/six.py", line 734, in reraise
File "urllib3/connectionpool.py", line 677, in urlopen
File "urllib3/connectionpool.py", line 392, in _make_request
File "http/client.py", line 1277, in request
File "http/client.py", line 1323, in _send_request
File "http/client.py", line 1272, in endheaders
File "http/client.py", line 1032, in _send_output
File "http/client.py", line 972, in send
File "docker/transport/unixconn.py", line 43, in connect
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "threading.py", line 926, in _bootstrap_inner
File "threading.py", line 870, in run
File "compose/cli/log_printer.py", line 168, in tail_container_logs
File "compose/cli/log_printer.py", line 185, in wait_on_exit
File "compose/container.py", line 268, in wait
File "docker/utils/decorators.py", line 19, in wrapped
File "docker/api/container.py", line 1305, in wait
File "docker/utils/decorators.py", line 46, in inner
File "docker/api/client.py", line 233, in _post
File "requests/sessions.py", line 578, in post
File "requests/sessions.py", line 530, in request
File "requests/sessions.py", line 643, in send
File "requests/adapters.py", line 498, in send
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
这是我的第一个 API(称为“层次结构”)的 docker-compose:
services:
backend:
build: ./
restart: always
labels:
- traefik.enable=true
- traefik.http.services.hierarchy_app.loadbalancer.server.port=80
- traefik.http.routers.hierarchy-http.entrypoints=http
- traefik.http.routers.hierarchy-http.rule=Host(`api.mydomain.me`)
- traefik.docker.network=traefik-public
- traefik.http.routers.hierarchy-https.entrypoints=https
- traefik.http.routers.hierarchy-https.rule=Host(`api.mydomain.me`)
- traefik.http.routers.hierarchy-https.tls=true
- traefik.http.routers.hierarchy-https.tls.certresolver=le
- traefik.http.middlewares.https-redirect.redirectscheme.scheme=https
- traefik.http.middlewares.https-redirect.redirectscheme.permanent=true
- traefik.http.routers.hierarchy-http.middlewares=https-redirect
networks:
- traefik-public
volumes:
- ${PWD}/hierarchy_app/commands.json:/hierarchy_app/commands.json:Z
networks:
traefik-public:
external: true
这是我的第二个 API(称之为“语音室”)的 docker-compose:
services:
backend:
build: ./
restart: always
labels:
- traefik.enable=true
- traefik.http.services.voicerooms_app.loadbalancer.server.port=80
- traefik.http.routers.voicerooms-http.entrypoints=http
- traefik.http.routers.voicerooms-http.rule=Host(`api.mydomain2.app`)
- traefik.docker.network=traefik-public
- traefik.http.routers.voicerooms-https.entrypoints=https
- traefik.http.routers.voicerooms-https.rule=Host(`api.mydomain2.app`)
- traefik.http.routers.voicerooms-https.tls=true
- traefik.http.routers.voicerooms-https.tls.certresolver=le
- traefik.http.middlewares.https-redirect.redirectscheme.scheme=https
- traefik.http.middlewares.https-redirect.redirectscheme.permanent=true
- traefik.http.routers.voicerooms-https.middlewares=https-redirect
networks:
- traefik-public
volumes:
- ${PWD}/voicerooms_app/commands.json:/voicerooms_app/commands.json:Z
networks:
traefik-public:
external: true
任何帮助将不胜感激,我一直试图解决这个问题一段时间:)
编辑:再向上滚动一点后,我在错误消息中发现了这一点:
backend_1 | [2022-01-10 02:04:51 +0000] [1] [INFO] Handling signal: term
backend_1 | [2022-01-10 02:04:51 +0000] [7] [INFO] Shutting down
backend_1 | [2022-01-10 02:04:51 +0000] [8] [INFO] Shutting down
我假设我的 docker 容器由于某种原因被终止,这是怎么回事?
我也遇到了和你一样的错误,我的问题是docker不启动。
检查 docker 状态
systemctl status docker
systemctl start docker
docker-compose up try again
systemctl enable docker
在启动时启动。
或者
如果您使用的是 Mac,则可能意味着 Docker 本身没有运行。 我已经重新启动了我的 Mac,并且 Docker 没有设置为在登录时自动启动。 您可以将其设置为 Docker 首选项。
或者你可以通过运行 sudo systemctl start docker 然后运行 sudo docker-compose up 来解决这个问题
似乎您的应用程序出于某种原因试图使用不存在的文件,并且它没有正确管理异常,从而使您的应用程序退出并且您的容器停止。
确保您在应用程序requests/adapters.py
中第 498 行的send
方法被正确封装到Try...Except
语句中。 此外,请确保记录异常,这将避免您的应用程序崩溃,但不会修复错误或根本原因 - 您必须单独调查。
您的应用程序由于某种原因而死亡,并且容器完成。 如何调试这是一个常见问题,我会以交互模式启动所有容器并检查发生了什么:
docker run --rm -p8080:80 -it <CONTAINER NAME>
而不是-p8080:80
(在主机的 8080 上公开容器的端口 80),添加您的网络设置...还添加您的容器需要的任何挂载/绑定/环境设置。
您也可以在bash
中启动容器并手动启动您的命令:
docker run --rm -p8080:80 -it <CONTAINER NAME> /bin/bash
从现在开始,您必须找出您的应用程序出了什么问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.