Hi Christian.
Yes it works with environment variable preset in container’s config however if the config is set from command line using -s lxc.include=extra-features.conf for a daemon container then it does not persist for subsequent lxc-attach.
My usecase requires config to be included at runtime rather than hardcoded in container’s config:
Extra configs are pre-installed on the device:
cat /usr/share/lxc/config/extra-features.conf | grep env
lxc.environment=FOOBAR=FOOBAR
Deploy vanilla container from images.linuxcontainers.org/images or a 3rd party linux application container:
lxc-create base -t download – -d debian -r stretch -a amd64
Enable device specific features in the container
App Containers (can be tools or host systemd managed services):
lxc-copy base -N app -s
lxc-execute app -s lxc.include=/usr/share/lxc/config/extra-features.app.conf --daemon
lxc-attach app – env | grep FOOBAR
echo $?
1
System containers:
lxc-copy base -N distro -s
lxc-start distro -s lxc.include=/usr/share/lxc/config/extra-features.system.conf
lxc-attach c1 – env | grep FOOBAR
echo $?
1
So in order to circumvent above issue i tried to reapply environment variables with lxc-attach by specifying rcfile with no success:
lxc-attach app --rcfile=/usr/share/lxc/config/common-env.conf – env | grep FOOBAR
echo $?
1
lxc-attach distro --rcfile=/usr/share/lxc/config/common-env.conf – env | grep FOOBAR
echo $?
1
Following solves the issue but is not desirable due to space constraints
lxc-create app -f lxc.include=/usr/share/lxc/config/extra-features.app.conf -t download
– -d debian -r stretch -a amd64
lxc-create distro -f lxc.include=/usr/share/lxc/config/extra-features.system.conf -t download
– -d debian -r stretch -a amd64
I had also considered following alternative to the above approach with no success:
lxc-copy base -N app -s --rcfile=/usr/share/lxc/config/extra-features.app.conf
lxc-copy: base: …/…/…/git/src/lxc/storage/storage.c: storage_copy: 336 No rootfs specified
lxc-copy: base: …/…/…/git/src/lxc/lxccontainer.c: copy_storage: 3571 Error copying storage.
lxc-copy: base: …/…/…/git/src/lxc/tools/lxc_copy.c: do_clone: 368 Failed to clone
My usecases target embedded system where containers are needed to extend features of a lean host device with priority on quick bringup and low memory footprint of container runtime for which lxc-execute is perfect. Storage and on-demand parallel execution of apps on same rootfs are resolved with lxc-copy --snapshot plus lxc-execute with -s lxc.include=feature.conf, the major pain point for me at the moment is: environment variables not persisting for subsequent lxc-attach.
Thanks
Mrinal