jupyterhub-deploy-docker icon indicating copy to clipboard operation
jupyterhub-deploy-docker copied to clipboard

Failed to connect to db: postgresql

Open wittfabian opened this issue 6 years ago • 3 comments

I noticed that the jupyterhub container initially has problems connecting to the database. I made the following changes to docker-compose.yml to solve the problem:

  • Update to version 2.1
  • Add healthcheck to hub-db service
  • Add healthcheck as condition to hub service "depends_on"
hub-db:
   ....
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 30s
      timeout: 30s
      retries: 3
  hub:
    depends_on:
      hub-db:
        condition: service_healthy

wittfabian avatar Mar 17 '18 18:03 wittfabian

I have the same problem. Can you post your complete docker-compose.yml file here?

RaRam avatar Apr 12 '18 14:04 RaRam

# JupyterHub docker-compose configuration file
version: "2.1"

services:
  hub-db:
    image: postgres:9.5
    container_name: jupyterhub-db
    restart: always
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      PGDATA: ${DB_VOLUME_CONTAINER}
    env_file:
      - secrets/postgres.env
    volumes:
      - "db:${DB_VOLUME_CONTAINER}"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 30s
      timeout: 30s
      retries: 3

  hub:
    depends_on:
      hub-db:
        condition: service_healthy
    build:
      context: .
      dockerfile: Dockerfile.jupyterhub
      args:
        JUPYTERHUB_VERSION: ${JUPYTERHUB_VERSION}
    restart: always
    image: jupyterhub
    container_name: jupyterhub
    volumes:
      # Bind Docker socket on the host so we can connect to the daemon from
      # within the container
      - "/var/run/docker.sock:/var/run/docker.sock:rw"
      # Bind Docker volume on host for JupyterHub database and cookie secrets
      - "data:${DATA_VOLUME_CONTAINER}"
    ports:
      - "9090:8000"
    links:
      - hub-db
    environment:
      # All containers will join this network
      DOCKER_NETWORK_NAME: ${DOCKER_NETWORK_NAME}
      # JupyterHub will spawn this Notebook image for users
      DOCKER_NOTEBOOK_IMAGE: ${LOCAL_NOTEBOOK_IMAGE}
      # Notebook directory inside user image
      DOCKER_NOTEBOOK_DIR: ${DOCKER_NOTEBOOK_DIR}
      # Using this run command (optional)
      DOCKER_SPAWN_CMD: ${DOCKER_SPAWN_CMD}
      # Postgres db info
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_HOST: hub-db
    env_file:
      - secrets/postgres.env
    command: >
      jupyterhub -f /srv/jupyterhub/jupyterhub_config.py

volumes:
  data:
    external:
      name: ${DATA_VOLUME_HOST}
  db:
    external:
      name: ${DB_VOLUME_HOST}
  shared:
    external:
      name: jupyterhub-data-shared

networks:
  default:
    external:
      name: ${DOCKER_NETWORK_NAME}

wittfabian avatar Apr 12 '18 14:04 wittfabian

Any news about that? I have the same issue.

Dmfama20 avatar Aug 25 '22 13:08 Dmfama20

Hi :wave: This is an old issue and the repository has been updated. If you have more questions please use the Jupyter community forum https://discourse.jupyter.org/.

manics avatar Dec 05 '22 00:12 manics