Created
January 22, 2014 03:30
-
-
Save ciastek/8553059 to your computer and use it in GitHub Desktop.
Run script in LXC container, non-interactive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create container with key authentication | |
sudo lxc-create -t ubuntu -n test -- -S /root/.ssh/id_rsa.pub | |
sudo lxc-start -n test -d | |
sudo lxc-wait -n test -s RUNNING | |
# enable passwordless sudo for ubuntu user | |
chroot /var/lib/lxc/test/rootfs sh -c "echo 'ubuntu ALL=NOPASSWD:ALL' > /etc/sudoers.d/ubuntu; chmod 440 /etc/sudoers.d/ubuntu" | |
# now you can run commands in container, example: install avahi-daemon | |
ssh `cat /var/lib/misc/dnsmasq.leases | grep --word-regexp test | awk '{print $3}'` -l ubuntu -o "StrictHostKeyChecking no" sudo apt-get install -y avahi-daemon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good gist thanks!
To get IP of running container you can use:
Grepping it out of the leases worked fine once but not after I destroyed and recreated the container.