Bitflake logo

Self-host DbGate with Docker Compose

Web-based client for SQL and NoSQL databases.

dbgate

postgres

postgres:17

postgres-postgres-data-init

busybox

postgres-postgres-socket-init

busybox

The steps below take a few minutes end to end.

  1. Docker compose setup and file
    save the generated compose and env files.
  2. Secret generation
    create the random passwords DbGate needs.
  3. Start DbGate with Docker Compose
    bring the stack up and check it's healthy.

Requirements

You'll need these installed on the machine you're deploying to:

Docker

Packages DbGate and everything it depends on into an isolated container, so it runs the same way on your machine as it does everywhere else.

Install guide

Docker Compose

Reads docker-compose.yml and starts everything in it together. Ships with Docker Desktop. On Linux servers it's usually a separate install.

Install guide

1. Docker compose setup and file

Create a folder for DbGate and save the file below into it as docker-compose.yml. It describes every container the stack needs — DbGate itself and any supporting services, such as its database — along with the ports, volumes and environment variables each one uses. You'll also need an empty .env file in the same folder; Docker Compose reads it automatically and uses it to fill in the ${VARIABLE} references you'll see in the file below.

docker-compose.yml

version: "3.9"
services:
  dbgate:
    image: dbgate/dbgate:latest
    restart: unless-stopped
    ports:
      - 3000:3000
    environment:
      CONNECTIONS: sampledb
      DATABASE_sampledb: bookshop
      ENGINE_sampledb: postgres@dbgate-plugin-postgres
      LABEL_sampledb: Sample PostgreSQL
      LOGIN: admin
      PASSWORD: ${SETUP_ADMIN_PASSWORD}
      PASSWORD_sampledb: ${RANDOM_DBGATE_PG_PASSWORD}
      PORT_sampledb: "5432"
      SERVER_sampledb: localhost
      USAGE_ANALYTICS: "false"
      USER_sampledb: postgres
      WORKSPACE_DIR: /data
    volumes:
      - data:/data
      - tmp:/tmp
  postgres:
    image: postgres:17
    restart: unless-stopped
    network_mode: service:dbgate
    environment:
      POSTGRES_DB: bookshop
      POSTGRES_PASSWORD: ${RANDOM_DBGATE_PG_PASSWORD}
      POSTGRES_USER: postgres
    volumes:
      - postgres-data:/var/lib/postgresql/data
      - postgres-socket:/var/run/postgresql
    configs:
      - source: postgres-bookshop.sql
        target: /docker-entrypoint-initdb.d/bookshop.sql
    depends_on:
      dbgate:
        condition: service_started
      postgres-postgres-data-init:
        condition: service_completed_successfully
      postgres-postgres-socket-init:
        condition: service_completed_successfully
  postgres-postgres-data-init:
    image: busybox
    volumes:
      - postgres-data:/var/lib/postgresql/data
    command:
      - chown
      - 999:999
      - /var/lib/postgresql/data
  postgres-postgres-socket-init:
    image: busybox
    volumes:
      - postgres-socket:/var/run/postgresql
    command:
      - chown
      - 999:999
      - /var/run/postgresql
volumes:
  data: null
  postgres-data: null
  postgres-socket: null
  tmp: null
configs:
  postgres-bookshop.sql:
    content: |
      CREATE TABLE authors (
        id serial PRIMARY KEY,
        name text NOT NULL,
        country text
      );
      CREATE TABLE books (
        id serial PRIMARY KEY,
        author_id integer NOT NULL REFERENCES authors(id),
        title text NOT NULL,
        published_year integer,
        price numeric(8,2) NOT NULL,
        stock integer NOT NULL DEFAULT 0
      );
      CREATE TABLE customers (
        id serial PRIMARY KEY,
        name text NOT NULL,
        email text UNIQUE NOT NULL,
        city text,
        created_at timestamptz NOT NULL DEFAULT now()
      );
      CREATE TABLE orders (
        id serial PRIMARY KEY,
        customer_id integer NOT NULL REFERENCES customers(id),
        ordered_at timestamptz NOT NULL DEFAULT now(),
        status text NOT NULL DEFAULT 'paid'
      );
      CREATE TABLE order_items (
        order_id integer NOT NULL REFERENCES orders(id),
        book_id integer NOT NULL REFERENCES books(id),
        quantity integer NOT NULL DEFAULT 1,
        PRIMARY KEY (order_id, book_id)
      );
      INSERT INTO authors (name, country) VALUES
        ('Ursula K. Le Guin', 'United States'), ('Terry Pratchett', 'United Kingdom'),
        ('Stanisław Lem', 'Poland'), ('Octavia E. Butler', 'United States'),
        ('Michael Ende', 'Germany'), ('Tove Jansson', 'Finland');
      INSERT INTO books (author_id, title, published_year, price, stock) VALUES
        (1, 'A Wizard of Earthsea', 1968, 9.99, 14), (1, 'The Left Hand of Darkness', 1969, 11.50, 6),
        (1, 'The Dispossessed', 1974, 12.00, 3), (2, 'Guards! Guards!', 1989, 8.99, 21),
        (2, 'Small Gods', 1992, 8.99, 9), (2, 'Going Postal', 2004, 9.49, 12),
        (3, 'Solaris', 1961, 10.99, 7), (3, 'The Cyberiad', 1965, 11.99, 4),
        (4, 'Kindred', 1979, 10.50, 11), (4, 'Parable of the Sower', 1993, 12.99, 5),
        (5, 'Momo', 1973, 9.00, 8), (5, 'The Neverending Story', 1979, 13.99, 10),
        (6, 'Finn Family Moomintroll', 1948, 7.99, 16), (6, 'The Summer Book', 1972, 9.99, 2);
      INSERT INTO customers (name, email, city, created_at) VALUES
        ('Ada Fischer', 'ada@example.com', 'Berlin', now() - interval '210 days'),
        ('Bruno Costa', 'bruno@example.com', 'Lisbon', now() - interval '160 days'),
        ('Chiara Rossi', 'chiara@example.com', 'Milan', now() - interval '120 days'),
        ('Daan de Vries', 'daan@example.com', 'Utrecht', now() - interval '95 days'),
        ('Elin Berg', 'elin@example.com', 'Uppsala', now() - interval '60 days'),
        ('Farid Haddad', 'farid@example.com', 'Lyon', now() - interval '30 days'),
        ('Greta Novak', 'greta@example.com', 'Ljubljana', now() - interval '12 days');
      INSERT INTO orders (customer_id, ordered_at, status) VALUES
        (1, now() - interval '200 days', 'delivered'), (2, now() - interval '150 days', 'delivered'),
        (1, now() - interval '110 days', 'delivered'), (3, now() - interval '100 days', 'delivered'),
        (4, now() - interval '80 days', 'delivered'), (5, now() - interval '45 days', 'delivered'),
        (2, now() - interval '20 days', 'shipped'), (6, now() - interval '9 days', 'shipped'),
        (7, now() - interval '3 days', 'paid'), (3, now() - interval '1 day', 'paid');
      INSERT INTO order_items (order_id, book_id, quantity) VALUES
        (1, 1, 1), (1, 7, 1), (2, 4, 2), (3, 2, 1), (4, 12, 1), (4, 11, 1), (5, 9, 1),
        (6, 13, 2), (6, 14, 1), (7, 6, 1), (8, 10, 1), (8, 3, 1), (9, 5, 1), (10, 8, 1);

Volumes

DbGate stores its data in named Docker volumes, so it survives container restarts and updates:

  • data mounted at /data: DbGate's workspace: saved queries, charts, diagrams, archives and installed plugins.
  • tmp mounted at /tmp: System temporary directory.

2. Secret generation

DbGate needs a few randomly generated secrets — for example, database passwords or an internal session key — before it can start. These are referenced from docker-compose.yml above but don't live in it, so they need to end up in your .env file. Pick one of the two options below.

Generating secrets…

3. Start DbGate with Docker Compose

From the folder with docker-compose.yml and .env, run:

Terminal

Start DbGate and all its supporting services in the background.

docker compose up -d

The -d flag runs the stack in the background so it keeps running after you close the terminal. Docker will pull the images the first time, which can take a minute or two.

To check on it afterwards: docker compose ps shows whether containers are healthy, and docker compose logs -f follows their logs if something looks wrong. Once it's running, open http://localhost:3000 in your browser.