Skip to content

OCIO y TECnología

  • Privacy Policy
Offcanvas

  • Register
  • Lost your password ?

OCIO y TECnología

  • Home » 
  • Tecnología » 
  • Docker » 
  • Docker volume with NFS driver

Docker volume with NFS driver

Emilio González Montaña 2020/03/07 0

One of the most needed feature to run a docker swarm is to manage volumes the most automatic way, so the orchestration is easier & cleaner.

Bind volumes are not a proper solution because it forces the swarm administrator to enable the same bind on every single node (or defining a label for bind enabled nodes and then restrict services by labels, not a clean solution neither).

Docker volume drivers

Docker supports more options than bind volumes or local volumes, one of the simpler drivers (at least because NFS is quite easy to be available and because docker deploys this driver in its core) is the NFS driver.

First of all an NFS share is needed, usually an IP address and a NFS share path, for instance IP 1.2.3.4 and share name /nfs/data-volume.

Ensure NFS client is installed in every node (typically is installed), for instance for Ubuntu:

sudo apt-get install -y nfs-common

Then inside the docker-compose.yml two things are required:

  1. First define a named volume at service as usual.
  2. Define a volume at volumes section using nfs volume type and passing the options to point to the NFS share.

Example

Let’s create a simple MariaDB service persisting data into a NFS volume, so it’s OK for the orchestrator to deploy the service in any of the nodes:

version: '3.7'
services:
  mariadb:
    image: mariadb:10.4.12
    environment:
      - MYSQL_USER=user
      - MYSQL_PASSWORD=password
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=db
    volumes:
      - type: volume
        source: mariadb_data
        target: /var/lib/mysql
volumes:
  mariadb_data:
    driver_opts:
      type: 'nfs'
      o: 'addr=1.2.3.4,nolock,soft,rw'
      device: ':/nfs/data-volume'

Troubleshooting

Several things could happen depending on your NFS configuration.

Permissions issues

It could happen that your NFS share is always accessible by an special user and any other user & group accessing it will generate invalid accesses. You can avoid this running the service with user ID and group ID of the NFS share.

...
services:
  mariadb:
    image: mariadb:10.4.12
    user: 501:1000
...

Disable copying data from container to volume

By default when you create a volume into a path in which the container has data, this data will be copied into the volume, you can avoid that (maybe you have more permission errors) with the nodata option.

...
services:
  mariadb:
    image: mariadb:10.4.12
...
    volumes:
      - type: volume
        source: mariadb_data
        target: /var/lib/mysql
        volume:
          nocopy: true
...

References

  • Docker compose reference for volumes at services
  • Docker compose reference for volumes

Comparte esto:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
Tags : Tags docker   docker-compose.yml   docker-swarm   MariaDB   NFS   volume
Share
facebookShare on FacebooktwitterShare on TwitterpinterestShare on Pinterest
linkedinShare on LinkedinvkShare on VkredditShare on ReddittumblrShare on TumblrviadeoShare on ViadeobufferShare on BufferpocketShare on PocketwhatsappShare on WhatsappviberShare on ViberemailShare on EmailskypeShare on SkypediggShare on DiggmyspaceShare on MyspacebloggerShare on Blogger YahooMailShare on Yahoo mailtelegramShare on TelegramMessengerShare on Facebook Messenger gmailShare on GmailamazonShare on AmazonSMSShare on SMS
Post navigation
Previous post

Using YAML anchors & aliases on docker-compose.yml

Next post

Managing remote docker instances

Emilio González Montaña

Related Posts

Categories Data bases  Docker  Tecnología Docker volume with NFS driver

Recover corrupted Postgres DB WAL

Categories Docker  Linux  Tecnología  Utils Docker volume with NFS driver

Install WSL2 + Docker on Windows

Categories Docker  Tecnología  YAML Docker volume with NFS driver

Docker swarm Traefik reverse proxy

Leave a Comment Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Detachable screens to avoid SSH disconnections
  • Expose WSL2 port to the network
  • Rosaleda (parque El Retiro, Madrid)
  • Back to the painting table
  • Recover corrupted Postgres DB WAL

Categories

  • Aficiones
  • AI
  • Bricolage
  • Data bases
  • Docker
  • Escenografía
  • Eventos
  • Fotografía
  • Hardware
  • Linux
  • Networking
  • Partidas
  • Proxmox
  • Sin categoría
  • Tecnología
  • Utils
  • Viajes
  • Virtualization
  • Warhammer
  • YAML

Tags

anthill (1) apt (5) cellular-automatons (1) ceph (2) context (1) conways-life (1) cortador (1) debian (3) docker (9) docker-compose.yml (4) docker-swarm (5) DRY (1) El Imperio (2) Enanos (2) escenografía (3) fotos (3) GlusterFS (1) Guerreros del Caos (2) informática (1) Linux (8) M.2 (1) Mac (1) Madrid (2) maqueta (2) MariaDB (2) miniaturas (4) MySQL (2) NFS (2) NVMe (1) partida (2) poliestireno (1) portainer (1) proxmox (2) rocas (1) Sony A65 (2) SSH (5) ssh-key (1) Ubuntu (8) update (2) volume (1) Warhammer (11) Windows (3) WSL (2) WSL2 (2) YAML (1)

Archives

  • June 2024
  • May 2024
  • April 2024
  • February 2024
  • January 2024
  • September 2023
  • August 2023
  • June 2023
  • December 2021
  • April 2021
  • May 2020
  • April 2020
  • March 2020
  • November 2019
  • July 2018
  • February 2017
  • June 2015
  • April 2014
  • April 2011
  • January 2011
  • July 2010
  • June 2010
  • March 2010
  • November 2009
  • June 2009
  • December 2008
  • November 2008
  • October 2008
  • June 2008
  • May 2008
  • October 2007

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright © 2025 OCIO y TECnología - Powered by Nevothemes.
Offcanvas