Introduction:
In this guide, we will walk through the process of mounting an SMB/CIFS file share for Docker containers managed by HashiCorp Nomad. SMB (Server Message Block) and CIFS (Common Internet File System) are network file sharing protocols that allow applications to read and write to files and request services from server programs in a computer network. By integrating SMB/CIFS file shares with Docker in Nomad, you can enable your containers to access shared storage resources, facilitating data sharing and collaboration across your applications.
Enable the Docker volume in your client config:
plugin "docker" {
config {
volumes {
enabled = true
}
}
}
Below is a job to dynamically create a CIFS Docker volume and mount it to a container:
job "cifs-example" {
datacenters = ["dc1"]
group "cache" {
network {
port "db" {
to = 6379
}
}
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
ports = ["db"]
mounts {
target = "/mount"
source = "myRedisCIFS"
volume_options {
no_copy = "false"
driver_config {
name = "local"
options {
type = "cifs"
device = "//192.168.1.123/Nomad"
o = "vers=3.0,dir_mode=0777,file_mode=0777,serverino,username=username,password=password"
}
}
}
}
}
resources {
cpu = 500
memory = 256
}
}
}
}
Please note that this job does not include any "cleanup" tasks (i.e. unmounting the volume) - it simply reproduces your original steps. However, we recommend that you include that logic if possible.
References:
https://developer.hashicorp.com/nomad/docs/drivers/docker#mounts