网络悬挂5秒钟的VS代码远程Docker容器

发布于 2025-02-13 05:58:28 字数 1231 浏览 0 评论 0原文

我有3个服务:WebApp(App),数据库(DB)和REDIS(RD)共享同一网络。 随机,与服务(数据库和REDIS)的两个连接均可悬挂5秒钟。 连接到数据库的网络服务器不仅在运行网络服务器时,即使我在网页上浏览链接时,也是如此。在某个时候,它冻结了,需要等待大约5秒钟。

我不确定,但是看起来连接在某个时候会自动关闭,需要重新建立。

我不知道我应该调试以下问题:

  • 在我的应用程序容器中运行Telnet DB 5432 telnet RD 5432 始终会立即工作。
  • 在我的主机机器中运行Docker PS -A显示以下显示:

这是我的docker-compose文件:

version: "3"

services:
  app:
    depends_on:
      - db
      - rd
    build:
      context: ..
      dockerfile: .devcontainer/service_app/Dockerfile

    volumes:
      - ..:/workspace:delegated

    # Avoid having the container shut down if the default container command fails or exits
    command: /bin/sh -c "while sleep 1000; do :; done"

  db:
    env_file: service_db/.env.local
    build:
      context: ..
      dockerfile: .devcontainer/service_db/Dockerfile
    volumes:
      - "pgdata:/var/lib/postgresql/data"

  rd:
    image: redis:7
    volumes:
      - "rddata:/data"

volumes:
  pgdata:
  rddata:

我不明白会导致这一点。谢谢。

I have 3 services: webapp (app), database (db), and redis (rd) that share the same network.
Randomly, both connections to the services (database and redis) hangs about 5 seconds.
It's not only when I run my webserver that connects to the database, but even when I browse a link on a web page. At some point it freezes and need to wait for about 5 seconds.

I'm not sure but it looks like the connection is automatically closed at some point and need to be re-established.

I don't know I'm supposed to debug this:

  • Running telnet db 5432 or telnet rd 5432 in my app container will always work instantly.
  • Running docker ps -a in my host machine display this:
    enter image description here

Here is my docker-compose file:

version: "3"

services:
  app:
    depends_on:
      - db
      - rd
    build:
      context: ..
      dockerfile: .devcontainer/service_app/Dockerfile

    volumes:
      - ..:/workspace:delegated

    # Avoid having the container shut down if the default container command fails or exits
    command: /bin/sh -c "while sleep 1000; do :; done"

  db:
    env_file: service_db/.env.local
    build:
      context: ..
      dockerfile: .devcontainer/service_db/Dockerfile
    volumes:
      - "pgdata:/var/lib/postgresql/data"

  rd:
    image: redis:7
    volumes:
      - "rddata:/data"

volumes:
  pgdata:
  rddata:

I don't understand what could cause this. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍白女子 2025-02-20 05:58:28

尝试用tail -f/dev/null替换睡眠环路

Try to replace your sleep loop with tail -f /dev/null

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文