Network hanging 5 seconds with VS Code remote Docker containers

Viewed 91

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.

1 Answers

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

Related