您好,我正在尝试使用 podman-compose 将 nfs 卷附加到我的 podman 容器上。
但是,它总是说
mount.nfs4: Failed to resolve server : Name or service not known
。怎么解决?
在我的终端(主机操作系统)中,它安装得很好,如您所见。
$ mount -t nfs XXX.XXX.XXX.XXX:/mnt/nfs1 /mnt/nfs1
$ mount | grep nfs
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
XXX.XXX.XXX.XXX:/mnt/nfs1 on /mnt/nfs1 type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=AAA.AAA.AAA.AAA,local_lock=none,addr=XXX.XXX.XXX.XXX)
但是,使用
podman-compose
,效果不太好。
docker-compose.yaml
version: "3"
services:
test-nfs:
image: "registry.access.redhat.com/ubi8/ubi:8.9-1136"
container_name: "test-nfs"
network_mode: "host"
privileged: true
restart: always
volumes:
- nfs1:/mnt/nfs1
volumes:
nfs1:
driver: local
driver_opts:
type: "nfs"
o: "addr=XXX.XXX.XXX.XXX"
device: ":/mnt/nfs1"
使用上面的文件,让我们运行容器。
$ podman-compose -f docker-compose.yaml up
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.9.4-dev
** excluding: set()
['podman', 'ps', '--filter', 'label=io.podman.compose.project=root', '-a', '--format', '{{ index .Labels "io.podman.compose.config-hash"}}']
podman volume inspect root_nfs1 || podman volume create root_nfs1
['podman', 'volume', 'inspect', 'root_nfs1']
podman create --name=test-nfs --label io.podman.compose.config-hash=8c0e9bc14a626047910a2c6fa6ad4eda5b6c094c538ae3a33c19656408c35904 --label io.podman.compose.project=root --label io.podman.compose.version=1.0.6 --label [email protected] --label com.docker.compose.project=root --label com.docker.compose.project.working_dir=/root --label com.docker.compose.project.config_files=docker-compose.yaml --label com.docker.compose.container-number=1 --label com.docker.compose.service=test-nfs -v root_nfs1:/mnt/nfs1 --network host --privileged --restart always registry.access.redhat.com/ubi8/ubi:8.9-1136
4c0bf4295b8aac36923e78ac26136fb0a5332f989512205fbb15d7c2f173a1e2
exit code: 0
podman start -a test-nfs
Error: unable to start container 4c0bf4295b8aac36923e78ac26136fb0a5332f989512205fbb15d7c2f173a1e2: mounting volume root_nfs1 for container 4c0bf4295b8aac36923e78ac26136fb0a5332f989512205fbb15d7c2f173a1e2: mount.nfs4: Failed to resolve server : Name or service not known
exit code: 125
我找到了我错过的路。
有两件事。
如果您在
docker-compose.yaml
中更改了卷内容,则应使用命令 podman volume rm <volume_name>
在 podman 卷中删除
不要将“addr=XXX.XXX.XXX.XXX”放在“o:”(选项)处。它不起作用(至少在 podman 中)像
device: "XXX.XXX.XXX.XXX:/mnt/nfs1"
一样,就像你在终端挂载时所做的那样。
以下是我的完整
.yaml
文件。我希望这对你有帮助。
* 仅供参考,我还测试了 cephfs。效果很好。
docker-compose.yaml
version: "3"
services:
test-nfs:
image: "registry.access.redhat.com/ubi8/ubi:8.9-1136"
container_name: "test-nfs"
network_mode: "host"
privileged: true
restart: always
volumes:
- nfs-test:/nfs_test
- cephfs:/images
entrypoint: ["tail", "-f", "/dev/null"]
volumes:
nfs-test:
driver: local
driver_opts:
type: "nfs"
o: "rw"
device: "XXX.XXX.XXX.XXX:/mnt/nfs1"
cephfs:
driver: local
driver_opts:
type: "ceph"
o: "name=<PUT_NAME>,secret=<PUT_SECRET>,fs=<CEPH_FS_VOLUME_NAME>"
device: "XXX.XXX.XXX.XXX:PORT_NUM:/"