Showing posts with label lxc. Show all posts
Showing posts with label lxc. Show all posts

Sunday, August 27, 2017

Ubuntu 12 04 Getting Started With LXC

Ubuntu 12 04 Getting Started With LXC


This tutorial is just going to get you hitting the ground running with LXC to prick your interest. As such there is no heavy manipulation of config files or advanced features.

To install LXC and get inside a container simply run the following commands:


sudo apt-get install lxc -y
sudo lxc-create --template ubuntu --name [CONTAINER NAME]

# Wait a significant period of time...

# Start the container and enter into it
sudo lxc-start -d --name [CONTAINER NAME]
sudo lxc-attach --name [CONTAINER NAME]

# have some fun in the container
# exit back out to the host with the "exit" command

# Stop the container when you are finished
sudo lxc-stop --name [CONTAINER NAME]

You can use lxc-start without the -d switch to start the container and automatically enter it. The username will be ubuntu and the password will also be ubuntu, but I had difficulties exiting properly and recommend always using the -d option shown above.

The templates are located at /usr/lib/lxc/templates. There are templates for busybox, debian, fedora, opensuse, sshd, ubuntu, and ubuntu-cloud. You can create your own but that is beyond the scope of this tutorial.

References

  • Ask Ubuntu - What is LXC and how to get started?

download file now

Read more »

Monday, August 21, 2017

Ubuntu 12 04 Set Docker To Use the LXC Container Engine

Ubuntu 12 04 Set Docker To Use the LXC Container Engine


As of Docker 0.9, docker does not use LXC by default for the container engine. However, one may find it useful to do so, in order to attach to running containers with a new TTY.

Method 1 - Installation Script

Simply copy the following script into a file and execute it with

sudo bash my-script.sh

#!/bin/bash

# Ensure running bash not sh etc
if ! [ -n "$BASH_VERSION" ];then
echo "this is not bash, calling self with bash....";
SCRIPT=$(readlink -f "$0")
/bin/bash $SCRIPT
exit;
fi

# Ensure running as root user
USER=`whoami`

if [ "$USER" != "root" ]; then
echo "You need to run me with sudo!"
exit
fi

apt-get update && apt-get install lxc -y
echo DOCKER_OPTS="-e lxc" >> /etc/default/docker
service docker restart

Method 2 - Manual Steps

    Ensure that you already have LXC installed by running the following command
    sudo apt-get install lxc -y
    Edit the /etc/default/docker file and adding "-e lxc" as shown below:
    Restart the docker service by running
    sudo service docker restart
    or by rebooting the server

References

  • Bindable - Make lxc-attach work again with docker 0.9
  • Stack Overflow - Docker-enter-running-container-with-new-tty

download file now

Read more »