alpine linux配置NFS服务

NFS客户端

  • 安装 nfs-utils :

alpine linux安装nfs-utils软件包
sudo apk add nfs-utils
sudo rc-update add nfsmount
sudo rc-service nfsmount start
  • 挂载NFS:

alpine linux挂载NFS
mkdir -p /data/build
mount -t nfs 172.18.0.1:/data/docs/github.com/cloud-atlas/build /data/build

alpine linux容器的NFS客户端

相同的方法,在 在kind运行简单的容器 ,运行 Alpine Docker镜像alpine-nginx 容器,我发现执行NFS挂载时候报错:

flock: unrecognized option: e
BusyBox v1.35.0 (2022-11-19 10:13:10 UTC) multi-call binary.

Usage: flock [-sxun] FD | { FILE [-c] PROG ARGS  }

[Un]lock file descriptor, or lock FILE, run PROG

        -s      Shared lock
        -x      Exclusive lock (default)
        -u      Unlock FD
        -n      Fail rather than wait

参考 Privileged doesn't work #10000 ,在运行容器时候,需要添加一个 --privileged=true 参数。那么对于 kubernetes 的运行容器,则需要有一个配置

  • 运行docker容器对比验证(没有 --privileged=true 参数 ):

    docker run --name alpine-nginx-nfs -it alpine-nginx:20221129-02 /bin/bash
    

容器内部使用 df -h 查看目录:

Filesystem                Size      Used Available Use% Mounted on
/dev/nvme0n1p8           44.7G      3.8G     40.6G   9% /
tmpfs                    64.0M         0     64.0M   0% /dev
shm                      64.0M         0     64.0M   0% /dev/shm
/dev/nvme0n1p8           44.7G      3.8G     40.6G   9% /etc/resolv.conf
/dev/nvme0n1p8           44.7G      3.8G     40.6G   9% /etc/hostname
/dev/nvme0n1p8           44.7G      3.8G     40.6G   9% /etc/hosts
tmpfs                    15.6G         0     15.6G   0% /proc/asound
tmpfs                    64.0M         0     64.0M   0% /proc/kcore
tmpfs                    64.0M         0     64.0M   0% /proc/keys
tmpfs                    64.0M         0     64.0M   0% /proc/timer_list
tmpfs                    15.6G         0     15.6G   0% /proc/scsi
tmpfs                    15.6G         0     15.6G   0% /sys/firmware
  • 运行docker容器对比验证( --privileged=true 参数 ):

    docker run --name alpine-nginx-nfs-priv --privileged=true -it alpine-nginx:20221129-02 /bin/bash
    

容器内部使用 df -h 查看目录:

Filesystem                Size      Used Available Use% Mounted on
/dev/nvme0n1p8           44.7G      3.9G     40.5G   9% /
tmpfs                    64.0M         0     64.0M   0% /dev
shm                      64.0M         0     64.0M   0% /dev/shm
/dev/nvme0n1p8           44.7G      3.9G     40.5G   9% /etc/resolv.conf
/dev/nvme0n1p8           44.7G      3.9G     40.5G   9% /etc/hostname
/dev/nvme0n1p8           44.7G      3.9G     40.5G   9% /etc/hosts

参考