Showing posts with label container. Show all posts
Showing posts with label container. Show all posts

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 »

Ubuntu Docker Enter Running Container With Nsenter

Ubuntu Docker Enter Running Container With Nsenter


Docker 0.11 has a new feature that allows direct host networking. Unfortunately this feature doesnt work when you set docker to use the LXC execution driver. Thus, I have found an alternative way to attach to a running container on Ubuntu, other than using lxc-attach.

This tutorial teaches you to use nsenter and not nsinit. I did initially try to use nsinit, but configuring it was not as simple (for me).

Steps

Compile the latest nsenter

#!/bin/bash
cd /tmp
curl http://bit.ly/1iLVbQU | tar -zxf-
cd util-linux-2.24

# Install the necessary tools to for make
sudo apt-get install build-essential -y

# Now compile!
./configure --without-ncurses
make nsenter

# Move nsenter into your execution PATH
sudo mv nsenter /usr/local/bin

Great, now you have nsenter. Here is a script I use to enter the first (and only) docker container I am running. I save it to "enter-first-container.sh" because its a bit much to keep copy and pasting.


#!/bin/bash
CONTAINER_ID=`docker ps --no-trunc | sed -n 2p | tr -s | cut -d -f1`
PID=`docker inspect --format {{ .State.Pid }} $CONTAINER_ID`
nsenter -m -u -n -i -p -t $PID /bin/bash

References


download file now

Read more »