Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ehough committed Jan 31, 2019
2 parents b9082f4 + 43808e1 commit b94f257
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 69 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.0.0] - 2019-01-31

### Changed
* Switch to Alpine Linux

## [1.2.0] - 2018-09-26

### Added
Expand Down
18 changes: 5 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
# Alpine can only be used if/when this bug is fixed: https://bugs.alpinelinux.org/issues/8470
ARG BUILD_FROM=debian:stretch-slim
ARG BUILD_FROM=alpine:latest

FROM $BUILD_FROM

# https://github.com/ehough/docker-nfs-server/pull/3#issuecomment-387880692
ARG DEBIAN_FRONTEND=noninteractive

# kmod is needed for lsmod, and libcap2-bin is needed for confirming Linux capabilities
RUN apt-get update && \
apt-get install -y --no-install-recommends nfs-kernel-server kmod libcap2-bin && \
apt-get clean && \
rm -rf /var/lib/apt/lists && \
\
RUN apk --update --no-cache add bash nfs-utils && \
\
# remove the default config files
rm -v /etc/idmapd.conf /etc/exports

# http://wiki.linux-nfs.org/wiki/index.php/Nfsv4_configuration
RUN mkdir -p /var/lib/nfs/rpc_pipefs && \
mkdir -p /var/lib/nfs/v4recovery && \
RUN mkdir -p /var/lib/nfs/rpc_pipefs && \
mkdir -p /var/lib/nfs/v4recovery && \
echo "rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0" >> /etc/fstab && \
echo "nfsd /proc/fs/nfsd nfsd defaults 0 0" >> /etc/fstab

Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A lightweight, robust, flexible, and containerized NFS server.

This is the only containerized NFS server that offers **all** of the following features:

- small (~15MB) Alpine Linux image
- NFS versions 3, 4, or both simultaneously
- clean teardown of services upon termination (no lingering `nfsd` processes on Docker host)
- flexible construction of `/etc/exports`
Expand Down Expand Up @@ -40,7 +41,7 @@ This is the only containerized NFS server that offers **all** of the following f
- `nfs`
- `nfsd`
- `rpcsec_gss_krb5` (*only if Kerberos is used*)

Usually you can enable these modules with: `modprobe {nfs,nfsd,rpcsec_gss_krb5}`
1. The container will need to run with `CAP_SYS_ADMIN` (or `--privileged`). This is necessary as the server needs to mount several filesystems *inside* the container to support its operation, and performing mounts from inside a container is impossible without these capabilities.
1. The container will need local access to the files you'd like to serve via NFS. You can use Docker volumes, bind mounts, files baked into a custom image, or virtually any other means of supplying files to a Docker container.
Expand All @@ -57,13 +58,13 @@ Starting the `erichough/nfs-server` image will launch an NFS server. You'll need
--cap-add SYS_ADMIN \
-p 2049:2049 \
erichough/nfs-server

Let's break that command down into its individual pieces to see what's required for a successful server startup.

1. **Provide the files to be shared over NFS**

As noted in the [requirements](#requirements), the container will need local access to the files you'd like to share over NFS. Some ideas for supplying these files:

* [bind mounts](https://docs.docker.com/storage/bind-mounts/) (`-v /host/path/to/shared/files:/some/container/path`)
* [volumes](https://docs.docker.com/storage/volumes/) (`-v some_volume:/some/container/path`)
* files [baked into](https://docs.docker.com/engine/reference/builder/#copy) custom image (e.g. in a `Dockerfile`: `COPY /host/files /some/container/path`)
Expand All @@ -80,7 +81,7 @@ Let's break that command down into its individual pieces to see what's required
-v /host/path/to/exports.txt:/etc/exports:ro \
... \
erichough/nfs-server

1. provide each line of `/etc/exports` as an environment variable

The container will look for environment variables that start with `NFS_EXPORT_` and end with an integer. e.g. `NFS_EXPORT_0`, `NFS_EXPORT_1`, etc.
Expand All @@ -103,35 +104,35 @@ Let's break that command down into its individual pieces to see what's required
1. **Use `--cap-add SYS_ADMIN` or `--privileged`**

As noted in the [requirements](#requirements), the container will need additional privileges. So your `run` command will need *either*:

docker run --cap-add SYS_ADMIN ... erichough/nfs-server

or

docker run --privileged ... erichough/nfs-server

Not sure which to use? Go for `--cap-add SYS_ADMIN` as it's the lesser of two evils.
1. **Expose the server ports**
You'll need to open up at least one server port for your client connections. The ports listed in the examples below are the defaults used by this image and most can be [customized](doc/ports.md).

* If your clients connect via **NFSv4 only**, you can get by with just TCP port `2049`:

docker run -p 2049:2049 ... erichough/nfs-server

* If you'd like to support **NFSv3**, you'll need to expose a lot more ports:

docker run \
-p 2049:2049 -p 2049:2049/udp \
-p 111:111 -p 111:111/udp \
-p 32765:32765 -p 32765:32765/udp \
-p 32767:32767 -p 32767:32767/udp \
... \
erichough/nfs-server

If you pay close attention to each of the items in this section, the server should start quickly and be ready to accept your NFS clients.

### Mounting filesystems from a client

# mount <container-IP>:/some/export /some/local/path
Expand All @@ -141,7 +142,7 @@ If you pay close attention to each of the items in this section, the server shou
* [Kerberos security](doc/feature/kerberos.md)
* [NFSv4 user ID mapping](doc/feature/nfs4-user-id-mapping.md)
* [AppArmor integration](doc/feature/apparmor.md)

## Advanced

* [customizing which ports are used](doc/advanced/ports.md)
Expand All @@ -154,7 +155,6 @@ Please [open an issue](https://github.com/ehough/docker-nfs-server/issues) if yo
## Remaining tasks
- switch to Alpine Linux once `nfs-utils` version 2.3.1-r4 (or higher) is released in a stable repo (maybe Alpine 3.9?). See [this bug](https://bugs.alpinelinux.org/issues/8470) for details
- figure out why `rpc.nfsd` takes 5 minutes to startup/timeout unless `rpcbind` is running
- add more examples, including Docker Compose
Expand Down
Loading

0 comments on commit b94f257

Please sign in to comment.