How To map Docker volumes to your VPSA volumes

This requires Docker 1.10.0+ but was tested in 18.03.1-ce.

This process was also tested on Ubuntu 16.04 Xenial. Variations will exist between environments

Pre-prep:

  • Create one or more server records in the VPSA GUI covering all necessary Docker hosts
  • Create all necessary NAS volumes on the VPSA GUI
  • Attach the NAS Volumes to the relevant Server records in the VPSA GUI
    • NFS is highly recommended
    • If interested in SMB/CIFS, it's recommended to initially test with 'Guest mode' enabled
  • On all docker hosts necessary, install 'nfs-common' for NFS support and 'cifs-utils' for smbfs/cifs
    • apt-get install nfs-common
    • apt-get install cifs-utils

 

Creating volumes on the Docker host manually:

The following is for NFS:

$ docker volume create --driver local \
    --opt type=nfs \
    --opt "o=addr=${VPSA_IP},rw,vers=4.0" \
    --opt "device=:/export/${VOLUMENAME}" \
    --name ${VOLUMENAME}

And this handles SMB/CIFS:

$ docker volume create --driver local \
    --opt type=cifs \
    --opt "o=user=Guest" \ # "o=user=Username,password=Password"
    --opt "device=//${VPSA_IP}/${VOLUMENAME}" \
    --name ${VOLUMENAME}

Essentially the underlying "local" Docker volume driver correlates to behavior of the standard Linux 'mount' command.

 

Sample docker-compose structures for the volumes:

volumes:
  nfsshare:
    driver: local
    driver_opts:
      type: nfs
      o: "addr=${VPSA_IP},rw,vers=4.0"
      device: ":/export/${VOLUMENAME}"
  cifsshare:
    driver: local
    driver_opts:
      type: cifs
      o: "user=Guest"
      device: "//${VPSA_IP}/${VOLUMENAME}"

 

Next Steps:

From here, you can start a container using named volumes.

$ docker create --name owncloud \
    -v nfsshare:/var/www/html \
    owncloud

 Or with docker-compose:

version: "3"

services:
  owncloud:
    image: owncloud
    restart: unless-stopped
    volumes:
      - nfsshare:/var/www/html

This can also be utilized with Docker Swarm clusters for centralized storage points or scaling/roaming containers.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.