Docker Community Forums

Share and learn in the Docker community.

Using Docker with NFS

I’ve been playing with Docker and configuring NFS mount to contain images and to be able to add NFS mount point to docker containers.

The steps below are from arch linux replace pacman with apt-get, yum etc. as needed

Install docker:  pacman -S docker
Start/Enable docker daemon:  systemctl start docker
Search for premade docker images:  docker search fedora
Mount share for docker images:
    mount /mnt/freenas
    mount -o bind /mnt/freenas/docker /var/lib/docker
Run docker container (will pull image if 1st time): docker  run -i -t ubuntu:14.04 /bin/bash
Add NFS mount for docker container
    mount /mnt/freenas (if not already mounted
    add -v option to docker run: docker run -t -i -v /mnt/freenas/:/mnt/docker ubuntu

From docker container NFS share is mounted and is R/W. Can be shared across containers and hosts

root@34300a3460c1:/# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/docker-0:36-327-34300a3460c11542484f2481d006b4404905a7a53526560d06b716e9ae9242da 9.8G 235M 9.0G 3% /tmpfs 4.0G 0 4.0G 0% /dev

shm 64M 0 64M 0% /dev/shm 4.8T 5.2G 4.8T 1% /etc/hosts 4.8T 5.2G 4.8T 1% /mnt/docker

tmpfs 4.0G 0 4.0G 0% /proc/kcore

1 Like

The technique I’m using above uses devicemapper as the storage driver and the docker images seem to be placed in a 100G sparse file “data”. /mnt/docker/devicemapper/devicemapper/data

Is there a way to use NFS and have the images be separate files (for backup etc.) or subvolumes such as when using btrfs as the storage driver?

Thanks in advance.

1 Like

I am doing the same thing as your mentioned. Would you mind sharing your exports file required for NFS.

@ Akshay, I have a test environment so I have a wildcard export with no_root_squash. I’m using freenas, but on linux nfs server /etc/exports would be something like :
/path/to/exported/directory *(rw,no_root_squash)

As long as your host can write a file into the NFS share then docker should work well. Test writing a file into the NFS mount to check if you have permissions.

1 Like

Interested to here if others are using docker over NFS both for mount NFS share to containers and as a shared persistent storage for the images. Especially interested if 1.7 made improvements for this.

1 Like

I’m running Docker on CoreOS and for reliability using a NFS built on Debian 7.
My NFSServer Options are: rw,sync,fsid=0,crossmnt,no_subtree_check,no_root_squash.
For explaination of each :

hello, I am using NFS as well, how is the performance of your docker environment?

Hey everyone. Not quite the same thing, but I wrote up a blog post about how we use NFS with docker volumes in Docker Trusted Registry. You can read about it here.

and here is an image that automates the NFS mounts and works in a swarm mode