Repository: https://github.com/sharedvolume/nfs-server-imageā
Releases: https://github.com/sharedvolume/nfs-server-image/releasesā
A lightweight, production-ready NFS v4 server container based on Alpine Linux. This enterprise-grade solution is specifically designed for modern containerized environments including Docker, Kubernetes, and cloud-native platforms, providing secure and reliable network file sharing capabilities.
# Basic usage
docker run -d --name nfs-server --privileged \
-v /path/to/share:/nfs \
-e SHARED_DIRECTORY=/nfs \
-p 2049:2049 \
sharedvolume/nfs-server:<version>
# Mount from client
sudo mount -t nfs4 <docker-host-ip>:/ /mnt/nfs
Note: Replace
<version>with your desired version tag
version: '3.8'
services:
nfs-server:
image: sharedvolume/nfs-server:<version>
container_name: nfs-server
privileged: true
restart: unless-stopped
environment:
- SHARED_DIRECTORY=/nfs
- PERMITTED=10.0.0.0/8 # Restrict to local network
volumes:
- ./data:/nfs
ports:
- "2049:2049"
networks:
- nfs-network
networks:
nfs-network:
driver: bridge
Note: Replace
<version>with your desired version tag
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-server
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nfs-server
template:
metadata:
labels:
app: nfs-server
spec:
containers:
- name: nfs-server
image: sharedvolume/nfs-server:<version>
env:
- name: SHARED_DIRECTORY
value: "/nfs"
- name: PERMITTED
value: "*"
- name: SYNC
value: "true"
ports:
- containerPort: 2049
name: nfs
- containerPort: 20048
name: mountd
- containerPort: 111
name: rpcbind
securityContext:
privileged: true
capabilities:
add:
- SYS_ADMIN
- SYS_MODULE
volumeMounts:
- name: nfs-data
mountPath: /nfs
readinessProbe:
exec:
command:
- sh
- -c
- "showmount -e localhost"
initialDelaySeconds: 20
periodSeconds: 15
livenessProbe:
exec:
command:
- sh
- -c
- "pgrep rpc.mountd && showmount -e localhost"
initialDelaySeconds: 30
periodSeconds: 30
volumes:
- name: nfs-data
persistentVolumeClaim:
claimName: nfs-pvc
---
apiVersion: v1
kind: Service
metadata:
name: nfs-server
spec:
selector:
app: nfs-server
ports:
- name: nfs
port: 2049
targetPort: 2049
- name: mountd
port: 20048
targetPort: 20048
- name: rpcbind
port: 111
targetPort: 111
type: LoadBalancer
Note: Replace
<version>with your desired version tag
| Variable | Required | Default | Description |
|---|---|---|---|
SHARED_DIRECTORY | ā | - | Path to export inside the container |
PERMITTED | ā | * | Allowed clients (IP, CIDR, hostname) |
READ_ONLY | ā | false | Set to any value for read-only access |
SYNC | ā | false | Set to any value for synchronous writes |
SHARED_DIRECTORY_2 | ā | - | Additional directory to export |
docker run -d --name nfs-readonly --privileged \
-v /data:/nfs \
-e SHARED_DIRECTORY=/nfs \
-e PERMITTED="192.168.1.0/24" \
-e READ_ONLY=true \
-e SYNC=true \
-p 2049:2049 \
sharedvolume/nfs-server:<version>
docker run -d --name nfs-multi --privileged \
-v /data1:/nfs/data1 \
-v /data2:/nfs/data2 \
-e SHARED_DIRECTORY=/nfs \
-e SHARED_DIRECTORY_2=/nfs/data2 \
-p 2049:2049 \
sharedvolume/nfs-server:<version>
This NFS server implementation follows security best practices and provides multiple layers of protection:
PERMITTED environment variable# Secure configuration example
docker run -d --name nfs-server-secure \
--privileged \
-v /secure/data:/nfs:ro \
-e SHARED_DIRECTORY=/nfs \
-e PERMITTED="192.168.1.0/24,10.0.0.0/8" \
-e READ_ONLY=true \
-e SYNC=true \
-p 2049:2049 \
sharedvolume/nfs-server:<version>
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-server-secure
spec:
template:
spec:
containers:
- name: nfs-server
image: sharedvolume/nfs-server:<version>
securityContext:
privileged: true
runAsNonRoot: false
readOnlyRootFilesystem: false
capabilities:
add:
- SYS_ADMIN
- SETPCAP
drop:
- ALL
env:
- name: PERMITTED
value: "10.244.0.0/16" # Kubernetes pod network
- name: READ_ONLY
value: "true"
UFW (Ubuntu)
# Allow NFS from specific network
sudo ufw allow from 192.168.1.0/24 to any port 2049
sudo ufw allow from 192.168.1.0/24 to any port 20048
sudo ufw allow from 192.168.1.0/24 to any port 111
iptables
# Allow NFS traffic from trusted network
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 2049 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 20048 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 111 -j ACCEPT
# Monitor NFS access logs
docker logs nfs-server | grep -E "(mount|access|denied)"
# Real-time monitoring
docker logs -f nfs-server | grep -E "(DENIED|FAILED|ERROR)"
# Verify security configuration
docker exec nfs-server cat /etc/exports
docker exec nfs-server netstat -tlnp
# Check for unauthorized access attempts
docker exec nfs-server grep "denied" /var/log/messages
If you discover a security vulnerability, please follow our Security Policyā :
The NFS server requires elevated privileges to manage kernel modules and bind to privileged ports. This is a fundamental requirement for NFS functionality:
# Recommended: Full privileged mode
docker run --privileged sharedvolume/nfs-server:<version>
# Alternative: Specific capabilities (may have limitations)
docker run --cap-add SYS_ADMIN --cap-add SETPCAP sharedvolume/nfs-server:<version>
securityContext:
privileged: true
# Required for NFS kernel module access
PERMITTED environment variable to restrict client access# Corporate network with multiple subnets
-e PERMITTED="10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
# Kubernetes cluster network only
-e PERMITTED="10.244.0.0/16"
# Single trusted host
-e PERMITTED="192.168.1.100"
# Set appropriate permissions on host
sudo chown -R 1000:1000 /path/to/shared/data
sudo chmod -R 755 /path/to/shared/data
# For read-only scenarios
sudo chmod -R 644 /path/to/shared/data
PERMITTED variableREAD_ONLY=true for immutable data scenarios# Kubernetes resource limits
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
# High-performance storage mounting
docker run -d --name nfs-server-performance \
--privileged \
-v /fast/storage:/nfs:rw,shared \
-e SHARED_DIRECTORY=/nfs \
-e SYNC=false \
--tmpfs /tmp:rw,noexec,nosuid,size=256m \
sharedvolume/nfs-server:<version>
#!/bin/bash
# NFS Server Health Check
echo "=== NFS Server Diagnostics ==="
# Check container status
docker ps | grep nfs-server
# Verify NFS services
docker exec nfs-server pgrep -l nfsd
docker exec nfs-server pgrep -l mountd
docker exec nfs-server pgrep -l rpcbind
# Test exports
docker exec nfs-server showmount -e localhost
# Network connectivity
docker exec nfs-server netstat -tlnp | grep -E "(2049|20048|111)"
echo "=== End Diagnostics ==="
# Check logs
docker logs nfs-server
# Verify privileged mode
docker inspect nfs-server | grep Privileged
# Check kernel modules on host
lsmod | grep nfs
# Test connectivity
telnet <nfs-server-ip> 2049
# Check exports
showmount -e <nfs-server-ip>
# Verify client has NFS utilities
# Ubuntu/Debian: apt-get install nfs-common
# RHEL/CentOS: yum install nfs-utils
# Check client IP is in PERMITTED range
docker logs nfs-server | grep "Permitted clients"
# Verify directory permissions in container
docker exec nfs-server ls -la /nfs
Minikube requires additional configuration for NFS servers:
# Enable required kernel modules
minikube ssh -- sudo modprobe nfs nfsd
# Use NodePort for external access
kubectl patch service nfs-server -p '{"spec":{"type":"NodePort"}}'
Enable verbose logging for troubleshooting:
docker run -d --name nfs-debug --privileged \
-v /data:/nfs \
-e SHARED_DIRECTORY=/nfs \
sharedvolume/nfs-server:<version>
# Watch logs in real-time
docker logs -f nfs-debug
/
āāā etc/
ā āāā exports # NFS exports configuration
āāā usr/bin/
ā āāā nfsd.sh # Main entrypoint script
āāā proc/fs/nfsd/ # NFS kernel interface
āāā var/lib/nfs/ # NFS state files
| Port | Protocol | Service | Purpose |
|---|---|---|---|
| 2049 | TCP | NFS | Main NFS traffic |
| 20048 | TCP | mountd | Mount requests |
| 111 | TCP/UDP | rpcbind | RPC port mapping |
We welcome contributions! Please see our Contributing Guideā for details.
# Clone repository
git clone https://github.com/sharedvolume/nfs-server-image.git
cd nfs-server-image
# Build locally
docker build -t nfs-server:dev .
# Test
docker run -d --name nfs-test --privileged \
-e SHARED_DIRECTORY=/tmp/test \
nfs-server:dev
# Run tests
docker logs nfs-test
We welcome bug reports and feature requests! Please use the following templates when creating issues:
When reporting bugs, please include the following information:
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior:
Expected behavior A clear and concise description of what you expected to happen.
Environment (please complete the following information):
Container logs
Writing SHARED_DIRECTORY to /etc/exports file
The PERMITTED environment variable is set.
The permitted clients are: *.
The READ_ONLY environment variable is unset or null, defaulting to 'rw'.
Clients have read/write access.
The SYNC environment variable is set, using 'sync' mode.
Writes will be immediately written to disk.
Displaying /etc/exports contents:
/nfs *(rw,fsid=0,sync,no_subtree_check,no_auth_nlm,insecure,no_root_squash)
Starting rpcbind...
Displaying rpcbind status...
program version netid address service owner
100000 4 tcp6 ::.0.111 - superuser
100000 3 tcp6 ::.0.111 - superuser
100000 4 udp6 ::.0.111 - superuser
100000 3 udp6 ::.0.111 - superuser
100000 4 tcp 0.0.0.0.0.111 - superuser
100000 3 tcp 0.0.0.0.0.111 - superuser
100000 2 tcp 0.0.0.0.0.111 - superuser
100000 4 udp 0.0.0.0.0.111 - superuser
100000 3 udp 0.0.0.0.0.111 - superuser
100000 2 udp 0.0.0.0.0.111 - superuser
100000 4 local /var/run/rpcbind.sock - superuser
100000 3 local /var/run/rpcbind.sock - superuser
Starting NFS in the background...
rpc.nfsd: knfsd is currently down
rpc.nfsd: Writing version string to kernel: -2 -3 +4.1 +4.2
rpc.nfsd: Created AF_INET TCP socket.
rpc.nfsd: Created AF_INET6 TCP socket.
Exporting File System...
Export completed
Starting Mountd in the background...
Startup successful.
Additional context Add any other context about the problem here, such as:
When requesting new features, please include:
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like A clear and concise description of what you want to happen.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Use case Describe the specific use case or scenario where this feature would be beneficial.
Additional context Add any other context, screenshots, or examples about the feature request here.
We actively support the following versions of the NFS Server container:
| Version | Supported |
|---|---|
| 1.x.x | ā |
| 0.x.x | ā ļø Limited Support |
We take security seriously. If you discover a security vulnerability, please follow these steps:
For Non-Critical Vulnerabilities
For Critical Vulnerabilities
Information to Include
We use Semantic Versioningā . See releasesā for changelog and upgrade notes.
latest: Latest stable release<version>-alpine-3.22.0: Specific version with Alpine versionv<version>-alpine-3.22.0: Tagged version format<major.minor>-alpine-3.22.0: Major.minor tagsNote: Replace
<version>placeholders with your specific version numbers
This project is licensed under the Apache License 2.0 - see the LICENSEā file for details.
The Apache 2.0 license allows for commercial use, modification, and distribution. It also provides patent protection and requires attribution in derivative works.
For production environments and enterprise deployments:
Content type
Image
Digest
sha256:299f82e2bā¦
Size
22.4 MB
Last updated
about 1 year ago
docker pull sharedvolume/nfs-server