LXC 3.0.2 Unable to set configs with lxc-attach name --rcfile=foo.conf


(Mrinal Dhillon) #1

Hello how is rcfile used with lxc-attach?

I tried the following with no success:

$ lxc-start ubuntu
$ echo lxc.environment=FOO=BAR > /root/test.conf
$ lxc-attach ubuntu --rcfile=/root/test.conf – env | grep FOO
$

So, if not environment then which properties can take effect from rcfile with lxc-attach to a running container.

Thank You
Mrinal


(Stéphane Graber) #2

@brauner


(Mrinal Dhillon) #3

@brauner please let me know


(Christian Brauner) #4

One option without an additional config file is:

brauner@wittgenstein|~
> lxc-attach c1 -v FOO=BAR -- env | grep FOO
FOO=BAR

(Christian Brauner) #5

Also works from config file when setting lxc.environment after the container has started for me:

brauner@wittgenstein|~
> cat .local/share/lxc/c1/config | grep env
lxc.environment=FOOBAR=FOOBAR
brauner@wittgenstein|~
> lxc-attach c1 -- env | grep FOO
FOOBAR=FOOBAR

(Mrinal Dhillon) #6

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


(Mrinal Dhillon) #7

@brauner original question still stands . How is rcfile used with lxc-attach? Thanks