3

I have a question about Hashicorp Nomad in connection with the Docker driver. I would like to create a Docker volume and then use it in a Nomad job, i.e. a container. I would find it best if I don't have to create the Docker volumes on the host beforehand. This would result in me having to create an incredible number of volumes and implement my own logic to decide which volumes are needed. So it would be nicest if I can create the volumes in the Nomad job definition and also mount them. Another difficulty is that I want to create Samba Docker volumes.

a) Is Nomad able to create Docker volumes at all? b) Is this also possible with Samba/ CIFS volumes?

Thanks in advance! :-)

Lsander
  • 53
  • 1
  • 4
  • `Is this also possible with Samba/ CIFS volumes?` What is a "samba volume"?? Samba has shares, to add a new share you have to modify server config. – KamilCuk Feb 16 '23 at 21:52

1 Answers1

0

Is Nomad able to create Docker volumes at all?

Nomad executes stuff. So execute stuff. Execute stuff to create volume. You have to connect to host docker.sock and execute docker commands on it.

job "example" {
  datacenters = ["dc1"]
  type = "service"
  group "create_my_volume" {
    task "create_my_volume" {
      driver = "docker"
      config {
        image = "docker"
        args = ["sh", "-xeuc", <<EOF
           if ! docker volume inspect myvolume; then
              docker volume create myvolume
           fi
           EOF
        ]
        mount {
          type = "bind"
          target = "/var/run/docker.sock"
          source = "/var/run/docker.sock"
        }
      }
    }
  }
}

You could add such task as pre-init task so the volume is created before starting.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111