ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.19k stars 392 forks source link

Support docker's nfs mount #899

Open stiller-leser opened 6 years ago

stiller-leser commented 6 years ago
Version

0.9.3rc0

ISSUE TYPE
container.yml
services:
  i-rely-on-nfs:
     volumes:
       - nfs-mount-in-container:my-nfs-server:/path/on/my-nfs-server/
SUMMARY

To quote from StackOverflow: "From docker 17.06, you can mount NFS shares to the container directly when you run it, without the need of extra capabilities." This can be done like this:

docker run -d --name my-container --rm -p \
--mount "type=volume,target=folder-in-container,volume-nocopy,volume-driver=local,volume-opt=type=nfs,volume-opt=device=my-nfs-server:/path/on/my-nfs-server,"volume-opt=o=addr=nfs_server""

I am aware that this could be done by installing the corresponding nfs-capabilities in the container itself and executing a mount before the actual files are needed. However, this would mean additional unwanted packages in the final container (which are then not needed anymore), i.e. in the case of getting installation files from these volumes.

Happy to clarify if needed.

EDIT

From what it looks ansible-container actually uses docker-compose. Am I right? If so, the following should be possbile: Extract of container.yml

services:
  i-rely-on-nfs:
    from: centos:7
    roles:
      - test
    entrypoint: /usr/bin/dumb-init
    command: tail -F /dev/null
    volumes:
      - nfs-mount:/mnt

volumes:
  nfs-mount:
    docker:
      driver: local
      driver_opts:
        type: nfs
        device: ':/path/on/my-nfs-server/'
        o: addr=my-nfs-server

However running tasks/main.yml:

- name: List /mnt
  command: ls -asl /mnt
  register: lsd
- debug: msg="{{lsd.stdout}}"
- debug: msg="{{lsd.stderr}}"

shows /mnt as empty.

docker inspect volume nfs-mount results in:

[
    {
        "CreatedAt": "2018-03-09T11:54:28Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/nfs-mount/_data",
        "Name": "nfs-mount",
        "Options": {},
        "Scope": "local"
    }
]

EDIT2

I have tried my setup in docker-compose. Using the following setup it works for docker-compose:

version: '3.2'

services:

  centos:
    image: centos:7
    volumes:
      - vol_collab:/mnt:nocopy
    command: /bin/sh -c "while true; do echo 'OK'; sleep 2; done"

volumes:
  vol_collab:
    driver_opts:
      type: nfs
      o: "addr=my-nfs-server,nolock"
      device: ":/path/on/my-nfs-server/"
$ docker inspect volume dockercompose_vol_collab
[
    {
        "CreatedAt": "2017-08-04T15:04:41Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "dockercompose",
            "com.docker.compose.volume": "vol_collab"
        },
        "Mountpoint": "/var/lib/docker/volumes/dockercompose_vol_collab/_data",
        "Name": "dockercompose_vol_collab",
        "Options": {
            "device": ":/path/on/my-nfs-server/",
            "o": "addr=my-nfs-server,nolock",
            "type": "nfs"
        },
        "Scope": "local"
    }
]

I then adapted my container.yml to:

version: "3.2"

services:
  test:
    from: centos:7
    roles: 
      - test
    entrypoint: /usr/bin/dumb-init
    command: tail -F /dev/null
    volumes:
      - nfs-mount:/mnt:nocopy

volumes:
  nfs-mount:
    docker:
      driver_opts:
        type: nfs
        device: ':/path/on/my-nfs-server/'
        o: 'addr=my-nfs-server,nolock'

unfortunately to no avail. It returned ERROR The container.yml file is invalid: '3.2' is not one of ['1', '2'] and the created volume was empty yet again:

$ docker volume inspect nfs-mount
[
    {
        "CreatedAt": "2018-03-09T14:32:52Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/nfs-mount/_data",
        "Name": "nfs-mount",
        "Options": {},
        "Scope": "local"
    }
]
gorshunovr commented 6 years ago

Would love to have it implemented. Thank you.