Before Docker was a thing...
Small bash script that manages LXC containers, performs operations on one of the containers or all configured containers at once.
All active containers should have:
- User with name same as container name -
sh
command assumes that all containers have user with the same name as container name. Sh commands are performed as this user. - Running ssh server -
cp
command usesscp
program to perform transfers between containers.
Simply download the script and make it an executable file.
BIN_DIR=~/bin # change this if you want
mkdir -p $BIN_DIR
wget https://github.com/muroc/lxc-tricks/raw/master/container \
-O $BIN_DIR/container
chmod +x $BIN_DIR/container
If BIN_DIR
is no on the PATH
, modify PATH
in rc file of your shell.
RC_FILE=~/.bashrc # change if you are not using bash
echo "PATH=$BIN_DIR:$PATH" >> $RC_FILE
. $RC_FILE
Each managed container needs configuration file at location
~/.c/${CONTAINER_NAME}
. Configuration file may be empty.
Following command creates empty configuration files for all lxc containers.
mkdir -p ~/.c
for C in `lxc-ls`; do touch ~/.c/$C; done
If no configuration files are present, the script will print warning message and manage all available lxc containers.
container help # prints detailed usage information
container start # starts all active containers
container browser start # starts container of name browser
container browser sh # starts shell in container browser as user browser
container browser # same as above sh is the default action
container browser sudo # starts root shell in container browser
Following command copies file /home/browser/Downloads/photo.jpg from container browser to container gamedev at location /home/gamedev/photo.jpg:
container cp browser:Downloads/photo.jpg gamedev:
Transfer is done using scp
program, so ssh servers running on the containers
are needed to perform the transfer.
Name of the container can be read from program name (busybox-like behavior). Creating symlink for each container shortens each command by 10 characters.
Following script creates symlink for container named browser:
BIN_DIR=~/bin
cd $BIN_DIR
ln -s container browser
Now we can operate on this container through symlink:
browser start
browser firefox https://github.com/muroc/lxc-tricks
browser stop
Push requests are very welcome.
- default USERNAME configuration for
sh
command - per-container username configuration for
sh
command to remove username prerequisite - per-container FORCE_TERMINAL configuration
cp
command based onlxc-usernsexec
to remove ssh prerequisite- Background section before Prerequisites
- gif-animated usage at the top of README.md file