X

Oracle Linux, virtualization , Enterprise and Cloud Management Cloud technology musings

  • September 7, 2017

Running Oracle Linux 5 applications in Oracle Cloud Infrastructure using lxc.

Oracle Cloud Infrastructure bare-metal servers and virtual machines require an EFI capable OS and as such we offer Oracle Linux 6 and Oracle Linux 7 images for customers to deploy their instances. Most applications are certified and support with these OS versions however in some rare cases a customer has an older application that requires something like Oracle Linux 4 or 5. While we currently cannot run these versions as native instances, it is possible to run Linux Containers on Oracle Linux with an OL4 or OL5 environment.

We have, for many years, supported lxc (https://blogs.oracle.com/wim/oracle-linux-containers) with Oracle Linux. lxc is great for system-containers, if you want to call it that, an entire OS environment ( basically "start /bin/init" ) whereas docker is more an application-container, start your app. Sure you can run /bin/init as your 'app' but lxc is a bit more tuned towards this model, I think. The generic lxc documentation can be found here.

lxc is fully supported on Oracle Linux 6 and Oracle Linux 7 and Oracle Linux 5 is fully supported as a container OS on top. So for customers that have a need to run older applications on older versions  of Linux in OCI, this is a great option.

To get started with lxc in Oracle Cloud Infrastructure, you first need to create a bare-metal server or VM instance using Oracle Linux 7 as the OS image, create your virtual cloud network, create a block volume, attach the block volume etc. I will assume that you are familiar with these steps.  I make one additional assumption around VNICs. The easiest way to set up the networking is by allocating a separate secondary VNIC for each container and pass this VNIC into the container. A quick tutorial is here.

In summary:

- Create a compartment, virtual cloud network and subnet

- Create an instance (BM or VM)

- Create and attach a block volume that will host the containers

- Create a number of  VNICs (1 per container)

- Install lxc

- Create and mount a filesystem on the block volume that holds the containers

- Create a container.

 

To install lxc, simply use yum on your Oracle Linux instance:

# yum install lxc

...

Dependencies Resolved

================================================================================
 Package         Arch          Version                  Repository         Size
================================================================================
Updating:
 lxc             x86_64        1.1.5-2.0.9.el7          ol7_latest        231 k
Updating for dependencies:
 lxc-libs        x86_64        1.1.5-2.0.9.el7          ol7_latest        219 k

Transaction Summary
================================================================================
Upgrade  1 Package (+1 Dependent package)

Total download size: 450 k
Is this ok [y/d/N]:

Make sure you use the latest version of lxc (1.1.5-2.0.9 or newer)

I suggest using btrfs as the container filesystem.

Assuming you created a block volume, it should show up as /dev/sdb:

$ cat /proc/partitions
major minor  #blocks  name

   8        0   48838656 sda
   8        1     556988 sda1
   8        2    8420348 sda2
   8        3   39808260 sda3
   8       16  134217728 sdb

Create a partition using fdisk, simply create 1 partition that uses the entire volume

$ fdisk /dev/sdb

Enter n (new partition), p (primary partition) 1 (first partition on new volume) and hit enter twice if you want to use the entire Block Volume.
Enter w to write the partition table out to disk.

This should now show up:

$ cat /proc/partitions
major minor  #blocks  name

   8        0   48838656 sda
   8        1     556988 sda1
   8        2    8420348 sda2
   8        3   39808260 sda3
   8       16  134217728 sdb
   8       17  134216704 sdb1

Next create your btrfs volume and mount it under /container:

$ mkfs.btrfs /dev/sdb1

$ echo "/dev/sdb1 /container btrfs defaults,noatime,_netdev 0 2" > /etc/fstab

$ mount -a

The installation of lxc already created the /container directory on your server.

Next up,  configure your secondary VNICs using the scripts referenced here. It is slightly different in a VM instance versus a BM instance.

Create your first lxc container. The syntax is as follows:

 lxc-create -n <container name> -t <template> -- -R <release>
- Specify a container name that you want to use, for instance "ol5".
- To create Oracle Linux containers use the "oracle" template.
- Release specifies which release of the container OS you want to use. We are creating an Oracle Linux 5 container so we use -R 5.latest
- For Oracle Linux 4,6 or 7, use the same "oracle" template and change <release> to 4.latest, 6.latest or 7.latest

$ lxc-create -n ol5 -t oracle -- -R 5.latest
Host is OracleServer 7.3
Create configuration file /container/ol5/config
Yum installing release 5.latest for x86_64
...
Added container user:oracle password:oracle
Added container user:root password:root
Container : /container/ol5/rootfs
Config    : /container/ol5/config
Network   : eth0 (veth) on lxcbr0

There is an additional configuration step required. The network configuration of the newly created container needs to be modified.

Modify the container configuration file
$ vi /container/ol5/config

change the following lines:

lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.hwaddr = 00:16:3e:xx:xx:xx <- where xx:xx:xx has assigned values

to

lxc.network.type = phys
lxc.network.link = ens2f0.vlan.1  or ens4 or whatever name of the secondary vnic interface created earlier was called
 

comment out or remove the lxc.network.hwaddr line
#lxc.network.hwaddr =

It is important to comment out the hwaddr line because we want to use the mac address of the interface created by the scripts.

veth gets changed to phys because we are effectively passing through the network interface directly to the container


Start the container

$ lxc-start -n ol5.1

Connect to the console

$ lxc-console -n ol5.1

The default root password is root. Please modify this after creating your container.

To exit the console, type ctrl-a q

Configure the network inside the container. To find the IP configuration for your VNICs from inside your instance, you can view this URL:

$ wget http://169.254.169.254/opc/v1/vnics/

Manually:

$ ifconfig eth0 10.0.2.3 netmask 255.255.255.0
$ route add default gw 10.0.2.1

Configure the network at start time by creating a new ifcfg script :

edit /etc/sysconfig/network-scripts/ifcfg-eth0

example:

DEVICE="eth0"
BOOTPROTO=none
ONBOOT=yes
TYPE="Ethernet"
IPADDR=10.0.2.3
PREFIX=24
GATEWAY=10.0.2.1
DEFROUTE=yes

 

To see which lxc containers are actively running type

$ lxc-ls --active

This container would be a supported Oracle Linux 5 environment running on Oracle Linux 7.

NOTE: Oracle Linux 5 has entered extended support. See here. Keep in mind that for Oracle Cloud subscription customers, Extended support is included with your subscription without any additional cost/fees.

 

 

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services