使用Ansible的Docker NFS卷 [英] Docker NFS volume using Ansible

查看:83
本文介绍了使用Ansible的Docker NFS卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个简单的示例,例如

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": ""
        }

因此,结论是存在错误,但是在哪里?可以吗码头工人py?码头工人?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆