使用 Ansible 的 Docker NFS 卷 [英] Docker NFS volume using Ansible
问题描述
举一个简单的例子,例如
Given a simple example such as
$ docker volume create --driver local \
--opt type=nfs \
--opt o=addr=192.168.1.1,rw \
--opt device=:/path/to/dir \
foo
我如何使用 Ansible 做同样的事情?我试过例如
How can I do the same using Ansible? I tried for example
- name: NFS volume mount
docker_volume:
driver: "local"
driver_options:
type: nfs
o: "addr=192.168.1.1,rw"
device: /path/to/dir
volume_name: foo
这将创建卷而不会出错,但当卷与 docker_container
模块一起使用时会失败.
Which will create the volume without errors but it will fail when the volume is used with docker_container
module.
TASK [oracle-database : docker_container] **************************************
fatal: [oracle]: FAILED! => {"changed": false, "msg": "Error starting container 1beb3254e25a8fe47cd78e803a2050f24020cf72e138472d7d14d963e02bec7f: 500 Server Error: Internal Server Error (\"{\"message\":\"error while mounting volume '/var/lib/docker/volumes/foo/_data': failed to mount local volume: mount /path/to/dir:/var/lib/docker/volumes/foo/_data, data: addr=192.168.1.1: invalid argument\"}\")"}
当我使用 Ansibe 创建卷时
When I create the volume using Ansibe
[root@oracle ~]# docker volume inspect oracle-dumps
[
{
"CreatedAt": "2020-08-31T02:07:14-07:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/foo/_data",
"Name": "foo",
"Options": {
"device": "/path/to/dir",
"o": "192.168.1.1,rw",
"type": "nfs"
},
"Scope": "local"
}
]
当我使用 docker volume create
手动创建卷时:
When I create the volume manually using docker volume create
:
[root@oracle ~]# docker volume inspect oracle-dumps
[
{
"CreatedAt": "2020-08-31T02:07:14-07:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/foo/_data",
"Name": "foo",
"Options": {
"device": "/path/to/dir",
"o": "192.168.1.1,rw",
"type": "nfs"
},
"Scope": "local"
}
]
标签属性放在一边,看起来几乎一样.
The labels attribute aside, looks pretty much the same.
docker inspect
容器的体积是一样的
{
"Type": "volume",
"Name": "oracle-dumps",
"Source": "/var/lib/docker/volumes/foo/_data",
"Destination": "/otherpath/to/dir",
"Driver": "local",
"Mode": "rw",
"RW": true,
"Propagation": ""
}
所以结论是有一个错误,但在哪里?可以吗?码头工人?码头工人?
So the conclusion is that there is a bug but where? Ansible? docker-py? Docker?
解决方法是
- name: Create dump volume
command:
cmd: "docker volume create --driver local --opt type=nfs --opt o=addr=192.168.1.1,rw --opt device=:/path/to/dir foo"
推荐答案
问题在于缺少 :
.设备路径应该是 :/path/to/dir
The problem is the missing :
. The device path should be :/path/to/dir
- name: NFS volume mount
docker_volume:
driver: "local"
driver_options:
type: nfs
o: "addr=192.168.1.1,rw"
device: :/path/to/dir
volume_name: foo
这篇关于使用 Ansible 的 Docker NFS 卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!