Oracle Linux Container LXC 7.3 on Oracle Linux 7.3

This article explains how to create a Linux Containers 7.3  LXC on Oracle Linux 7.x, while creating an interface network as a bridge with a dedicated network address.

Plan:

  1. Install the pre-requis LXC container:
  2. Creation of Oracle Linux container 7u3.
  3. Set up a static IP address for Linux Container:

1. Install the pre-requis:

We have as a host, ORACLE Linux 7.3

# cat /etc/oracle-release
Oracle Linux Server release 7.3

# uname -a
Linux ol7-lxc.wadhahdaouehi.tn 3.8.13-118.16.3.el7uek.x86_64 #2 SMP Wed Feb 8 17:43:34 PST 2017 x86_64 x86_64 x86_64 GNU/Linux

a. Install the dedicated packages of the Linux containers.

Note: If  you want to Create the containers LXC on a File system BTRFS, then install the package btrfs-progs.

# yum install btrfs-progs lxc -y

Note: If you want to Create the containers LXC on a File system like XFS, then just install the package LXC because the File system XFS is built in Oracle Linux 7.x

# yum install lxc -y

b. Creation of the Filesystem container XFS.

Note: We can create btrfs file system on the disk and to use his feautures on cloning existing LXC container, but in my tutorial, I am going to use the filesystem XFS.

# fdisk /dev/sdb
# mkfs.xfs /dev/sdb1
# mount /dev/sdb1 /container

c. Sheck the Oracle Linux container templates:

The templates are located as script under the folder: /usr/share/lxc/templates

# ls /usr/share/lxc/templates
lxc-alpine     lxc-busybox  lxc-debian    lxc-gentoo        lxc-oracle  lxc-ubuntu
lxc-altlinux   lxc-centos   lxc-download  lxc-openmandriva  lxc-plamo   lxc-ubuntu-cloud
lxc-archlinux  lxc-cirros   lxc-fedora    lxc-opensuse      lxc-sshd

2. Creation of Oracle Linux container LXC 7u3:

Linux container creation requires the yum repository be available. I am going to use the public YUM repository.

  • container name:  ol7u3.wadhahdaouehi.th
  • template name: -t oracle
  • release name: –release 7.3

# lxc-create -n ol7u3.wadhahdaouehi.tn -t oracle -- --release=7.3
..........
Complete!
Rebuilding rpm database
Patching container rootfs /container/ol7u3.wadhahdaouehi.tn/rootfs for Oracle Linux 7.3
Configuring container for Oracle Linux 7.3
Added container user:oracle password:oracle
Added container user:root password:root
Container : /container/ol7u3.wadhahdaouehi.tn/rootfs
Config    : /container/ol7u3.wadhahdaouehi.tn/config
Network   : eth0 (veth
veth) on lxcbr0

Note: After the creation of the Oracle Linux template the password of the user root is root and the user oracle is oracle as a password.

a. Verify the Configuration file of our container:

#cat /container/ol7u3.wadhahdaouehi.tn/config
# Template used to create this container: /usr/share/lxc/templates/lxc-oracle
# Parameters passed to the template: --release=7.3
# For additional config options, please look at lxc.container.conf(5)
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:06:92:09
lxc.rootfs = /container/ol7u3.wadhahdaouehi.tn/rootfs
# Common configuration
lxc.include = /usr/share/lxc/config/oracle.common.conf
# Container configuration for Oracle Linux 7.3
lxc.arch = x86_64
lxc.utsname = ol7u3.wadhahdaouehi.tn
lxc.cap.drop = sys_resource
# Networking
lxc.network.name = eth0
lxc.network.mtu = 1500

 

b. Start / stop the container:

The option –name or -n to specify the container name.

lxc-start --name ol7u3.wadhahdaouehi.tn
# lxc-stop --name  ol7u3.wadhahdaouehi.tn
# lxc-autostart -n ol7u3.wadhahdaouehi.tn

c. Connect to the container:

Method 1: Using the tool lxc-attach

# lxc-attach  -n ol7u3.wadhahdaouehi.tn

Method 2: Using the SSH connection after configuring the network, check next step.

3.  Set up a static IP address for Linux Container:

Notelxcbr0 – network bridge which was created automatically when the lxc tools have been installed.

a. I have chaged the bridge ip address to 192.168.20.1 on /etc/sysconfig/lxc-net

#grep ^LXC /etc/sysconfig/lxc-net
LXC_BRIDGE="lxcbr0"
LXC_ADDR="192.168.20.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="192.168.20.0/24"

b. Change the configuration file of the container: /container/ol7u3.wadhahdaouehi.tn/config

# Networking
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.name = eth0
lxc.network.hwaddr = 00:16:3e:3b:b8:50
lxc.network.mtu = 1500
lxc.network.ipv4 = 192.168.20.201/24

c. Adding an other bridge interface lxcbr1:

# brctl addbr lxcbr1
# ifconfig lxcbr1 172.16.20.1/24
# ifconfig lxcbr1
lxcbr1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.20.1  netmask 255.255.255.0  broadcast 172.16.20.255
        inet6 fe80::a80d:ceff:feb9:f310  prefixlen 64  scopeid 0x20<link>
        ether aa:0d:ce:b9:f3:10  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 2957 (2.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Conclusion:

Creation of Oracle Linux 7.x container on the host Oracle Linux 7.3 and configuring the network connection.

 

Bookmark the permalink.
Loading Facebook Comments ...

One Response to Oracle Linux Container LXC 7.3 on Oracle Linux 7.3

  1. Pingback: Internet connection with a DHCP on my Oracle Linux LXC 7.3 – Wadhah DAOUEHI

Leave a Reply