Error working Nomad volumes

job "boundary-postgres" {
  datacenters = ["dc1"]
  type = "service"

  group "postgres" {
    count = 1

    volume "postgres_data" {
      type      = "host"
      read_only = false
      source    = "postgres_data"
    }

    network {
      port "db" {
        static = 5555
        to     = 5432
      }
    }

    task "postgres" {
      driver = "docker"

      config {
        image = "postgres"
        ports = ["db"]

        mount {
          type     = "volume"
          target   = "/var/lib/postgresql/data"
          source   = "postgres_data"
          readonly = false
        }
      }

      env {
        POSTGRES_USER     = "root"
        POSTGRES_PASSWORD = "rootpassword"
        POSTGRES_DB       = "boundary"
        PGDATA            = "/var/lib/postgresql/data/pgdata"
      }

      logs {
        max_files     = 5
        max_file_size = 15
      }

      resources {
        cpu    = 1000
        memory = 1024
      }

      volume_mount {
        volume      = "postgres_data"
        destination = "/var/lib/postgresql/data"
        read_only   = false
      }
    }

    restart {
      attempts = 10
      interval = "5m"
      delay    = "25s"
      mode     = "delay"
    }
  }
}

In my nomad client i have this:

host_volume "postgres_data" {
  path      = "/mnt/brimble-volume/postgres"
  read_only = false
}

I keep getting this error, Failed to create container configuration for image “postgres” (“sha256:b781f3a53e61df916d97dffe6669ef32b08515327ee3a398087115385b5178f5”): volumes are not enabled; cannot mount volume: “postgres_data”

Hi. Remove:

mount {
          type     = "volume"
          target   = "/var/lib/postgresql/data"
          source   = "postgres_data"
          readonly = false
}

What is that mount {} block doing there? What was your intention here?

mount {} refers for docker volume named postgres_data. Did you create such docker volume on the host the job is going to run? I think you are mixing nomad volumes with docker commands.

If you are using nomad volumes, just use volume and volume_mount blocks.

Or if you want to use docker volumes, remove both volume_mount and volume block which are for nomad volumes, and just use docker mounts. You have to enable them first in nomad agent configuration.

If you are using both with the same destination, one of them is going to overwrite the other, depending on the option order to docker daemon, so it’s odd they have the same "/var/lib/postgresql/data" destination.

Hi,

maybe have a look at my Immich setup, which is using Consul Connect to tie the Immich app and Postgres together.

I hope it’s not too complicated, just ignore/delete the worker and machine-learning groups.
The metrics stuff is for Prometheus monitoring, and the tags for Traefik. You can probably ignore both right now.