3

I would like to expose to a container (Ubuntu 16.04 created with debootstrap) started with systemd-nspawn a directory of the host system (also an Ubuntu 16.04). Is this possible with systemd-nspawn?

I would fallback on some NFS based solution (the host exposes the directory which is mounted by the guest) but a systemd native solution would be ideal.

WoJ
  • 1,445
  • 1
  • 19
  • 38
  • Would the `--bind` option work for you? – Stephen Harris Jul 19 '16 at 19:19
  • @StephenHarris: I do not know how I could have missed that in the [documentation](https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html#--bind=). Thanks. If you do not mind to turn the comment into an answer I will gladly accept it as this is exactly what I was looking for. – WoJ Jul 19 '16 at 19:22

1 Answers1

7

The systemd-nspawn command has a --bind option that lets you "bind mount" a directory from the host filesystem into the container.

If you just do --bind /path/to/dir then it will appear in that name inside the container.

If you do --bind /path/to/dir:/foo then it will show up as /foo inside the container.

In order to use it in a configuration file (/etc/systemd/nspawn/<container>.nspawn), add the Bind= directive to its [Files] section.

WoJ
  • 1,445
  • 1
  • 19
  • 38
Stephen Harris
  • 42,369
  • 5
  • 94
  • 123
  • And what about file system permissions? The bound directory is owned by nobody:nogroup user, right? What if I want to bind mount my host's `/home` directory to the containers `/home` directory, how do I do that properly? And even more, is there a way to inherit host's list of users (real users) by a container? – krokoziabla Sep 20 '17 at 18:39
  • @krokoziabla you should really create a new question explaining your setup and problem, what you're trying to achieve and what you've tried so far. – Stephen Harris Sep 21 '17 at 00:47
  • Done :-) https://unix.stackexchange.com/questions/393584/systemd-nspawn-file-system-permissions-for-a-bound-folder – krokoziabla Sep 21 '17 at 08:40