[Lxc-users] Executing a command inside a container?

Dan Kegel dank at kegel.com
Wed Aug 29 23:02:23 UTC 2012


Man, this has got to be an FAQ.

I'm merrily scripting buildbot setup inside a container, and tried to do
  sudo lxc-start -n foo  sh my-existing-setup-script.sh
where my-existing-setup-script.sh does, among other things,
  sudo apt-get install python-dev
(or, if the guest is running centos, some yum thing).

The first problem: apt-get hangs when it prompts the user for input.
I worked around that by adding -y, but then found that the network
is not up;
  sudo lxc-start -n foo -- ifconfig -a
shows no IP addresses.

So... I guess I have to actually start the system to run my
script inside the container.  I could use ssh to execute the
command... but there's no easy way to find out what IP
address to ssh to.  lxc-start doesn't make the host show up
in dns or the hosts file (should it?).

I see lxc-start-ephemeral has about 70 lines of script to do
just this: get the ip, wait for ssh to come up, and run a command
via ssh.

Is my easiest path to steal that code from lxc-start-ephemeral
and create a command lxc-ssh that ssh's into a container given
its name?  Or does something like this already exist?

I see
http://www.stgraber.org/2012/07/17/easily-ssh-to-your-containers-and-vms-on-ubuntu-12-04-lts/
which claims to make ssh'ing in easy, but it solves a different problem.

https://dev.launchpad.net/Running/LXC seems to indicate that
the way to do this is install avahi-daemon inside the container, but I'd
like to avoid relying on avahi.




More information about the lxc-users mailing list