Writeable filesystem option
There's some use cases where a program needs to write to, i.e., /etc In my case, after installing apache and copying a virtualhost I need to restart the service, but it fails trying to write to /var/logs. How can we achieve this?
BTW, thanks a lot for making this :)
There are currently three options:
-
Tmpfs mount, that's what I'm using for logs most of the time, because it cleans up on restart:
containers: apache: setup: ... - !EnsureDir /var/logs volumes: /var/logs: !Tmpfs { size: 1Mi } -
Bind directory from project dir (you need to create
tmp/logsdirectory under you workdir manually):volumes: /var/logs: !BindRW /work/tmp/logs -
The
write-mode: transient-hard-link-copyin command definition. It's mostly used for building packages. It's probably not what you want, just list here for completeness.
http://vagga.readthedocs.org/en/latest/volumes.html
I've tried all three options: 1 & 2. For empty dirs like /var/logs is ok, but not for /etc or /var. There are a lot of programs which needs to rewrite its config in /etc. Or in my case, 'service apache2 restart' needs to write to /var/run. 3. It needs to be done while building the container, not as a separate command.
- It needs to be done while building the container, not as a separate command.
I'm not sure what you mean? It's primary usage is to build package. So I use one ubuntu container for building application and to run it and to build docs, etc. The commands should be fast. And transient-hard-link-copy is slow. But when I want to do a release, I use the same container with transient-hard-link-copy option and checkinstall to build package (a second startup time is not too bad in this case)
Also see the warning in the documentation for this option.
1 & 2. For empty dirs like /var/logs is ok, but not for /etc or /var. There are a lot of programs which needs to rewrite its config in /etc. Or in my case, 'service apache2 restart' needs to write to /var/run.
Well, I don't know why you need to write to /etc, it's usually bad idea. The /var/run folder is usually tmpfs on real systems anyway, so you just need to mount tmpfs there (or it usually a symlink to /run so mount tmpfs to /run)
So anyway there are two ways to get pre-filled writable folder:
- Create a separate command to pre-fill folder for
!BindRW, i.e.vagga initcommand which run "mysql_install_db" andvagga runwhich runs mysql. This means "init" command should be run only once - Use a hack with a command as part of build process
!Sh "rm -rf /work/tmp/mysql; mkdir -p /work/tmp/mysql; cp -R /var/lib/mysql /work/tmp/mysql". It works, but should be used as last resort
Note that (2) will overwrite the data whatever image is rebuilt (and it happen without any confirmation, say when you do "git pull" and someone else changed vagga.yaml), but you can put more complex logic in the script if you want. And (1) requires sometimes run "mysql_upgrade" manually to upgrade local database when version changed.
For my cases vagga init is usually sufficient.
Was this helpful? Should issue be closed now?