Creating an Oracle Linux ASM Docker Image over Ubuntu 14.04

Prerequisites

  • 64-bit Ubuntu 14.04 server

General Information

In this setup we are:

  • Installing Docker
  • Creating a non-root user with Sudo and Docker privileges (axxana)
  • ASM device is /dev/sdb1.
  • Enabling SQLNET and SSH to the container
  • The default ASM port is 1521.
  • The SSH port is 2222.
  • The password for root and grid OS users in the container is axxana.
  • The password for sys ASM user is axxana.
  • The grid software is 12.2 without any patches.
  • The container operating system is Oracle Linux 7.5.
  • Within the container, there is no use of UDEV / ASMLIB or ASMFD: asm_diskstring=’/dev/asm*’,’/bbx/data/*’,’/dev/*’
  • All tests are done on regular Ubuntu 14.04 and on Axxana’s ISO (based on 14.04).
  • There is a crontab job to keep 15 days of trace files and remove audit files.

Apply UDEV rules to make sure the device has permissions of the same container IDs:

vi /etc/udev/rules.d/100-asm.rules

KERNEL==”sdb1“, NAME=”ASM_DISK”, OWNER=”54421″, GROUP=”54421″, MODE=”0660″

 

udevadm trigger –sysname-match=sdb1 –verbose

Verify the device has ASM labels:

DISK_GROUP=$( blkid | grep oracleasm | sed ‘s/.*LABEL=\”\([^\”]*\)\” TYPE=\”oracleasm\”/\1/’)

if [ -z “$DISK_GROUP” ]

then

echo “device /dev/sdb1 has not asm metadata”

else

echo “device /dev/sdb1 has diskgroup $DISK_GROUP”

fi

Install Docker

On Black Box as root:

curl -fsSL https://get.docker.com/ | sh

or:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –

add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

apt-get update

apt-cache policy docker-ce

apt-get install -y docker-ce

 

service docker status

Add Users

On Black Box as root:

Add equivalent user IDs to the docker to follow (will be identified from outside):

groupadd -g 54422 asmadmin

useradd -u 54421 -g 54422 grid

Add a dedicated user to manage the docker:

adduser axxana -g 54422

echo “axxana:axxana” | chpasswd

usermod -aG docker axxana

usermod -aG sudo axxana

sed -i ‘/PasswordAuthentication/d’ /etc/ssh/sshd_config ; echo “PasswordAuthentication no” >> /etc/ssh/sshd_config

sed -i ‘/PubkeyAuthentication/d’ /etc/ssh/sshd_config ; echo “PubkeyAuthentication yes” >> /etc/ssh/sshd_config

sed -i ‘/ChallengeResponseAuthentication/d’ /etc/ssh/sshd_config ; echo “ChallengeResponseAuthentication no” >> /etc/ssh/sshd_config

service ssh reload

Build a New Image

If you already have an image file, skip to the section below, titled Load Image.

In this step, we will create a new image from scratch, and then pack it at the end. Ensure you have the following file: \\nas\shared\oracle_tools\DockerASM\docker_asm_build_scripts.tar.gz

You can run /depo/build.sh + /depo/export.sh or you can run the following manual steps:

Prepare the Files

On Black Box as root:

scp docker_asm_build_scripts.tar.gz /tmp

mkdir /depo/

chown -R root:54422 /depo/

chmod 775 /depo

tar xvfz –same-owner /tmp/docker_asm_build_scripts.tar.gz -C /depo/

rm -f /tmp/docker_asm_build_scripts.tar.gz

 

List of the files

Script

Description

adrci_script.sh

Runs for crontab to delete trace files periodically

build.sh

Builds a docker image

clean.sh

Cleans all docker containers and an image

crontab.setup

A crontab job script for grid users; deletes trace files periodically

disks.sql

An SQL script for listing disks

docker_descendants.py

Checks docker images dependencies

docker_folder/Dockerfile

Builds instruction for docker image

export.sh

Exports a docker image and compresses it

glogin.sql

Establishes settings for proper formatting of  SQL*Plus output

grants.sql

Grants database permission during the build process

init+ASM.ora

The initialization file for ASM instance

install_grid.sh

Installs script for grid

linuxx64_12201_grid_home.zip

Oracle 12.2 grid software (no patches)

listener.ora

Listener file

oracle_asm

Logrotate for Oracle logfiles

rlwrap-0.42-1.el7.x86_64.rpm

Handy tool to enable history in SQL*Plus, asmcmd

run.sh

Starts a container

status.sh

Provides images and container status

Run the Build Image

On Black Box as root/axxana:

cd /depo/docker_folder

docker build -t ynixon/docker_grid_asm .

Run the image detached (at background):

docker run –rm –privileged –detach –name asm_grid_build -h gridserver -p 1521:1521 -p 2222:22 –shm-size 2048m -e TZ=UTC -v /sys/fs/cgroup:/sys/fs/cgroup:ro –volume /depo:/software –volume /boot:/boot –device=/dev/sdb1 ynixon/docker_grid_asm

Install the grid software:

docker exec -it asm_grid_build su – grid -c ‘/software/install_grid.sh’

Save the image with the grid:

docker commit -m “oracle linux 7.5 standalone grid infrastructure with ASM” -a “Yossi Nixon <Yossi.Nixon@Axxana.com>” asm_grid_build ynixon/axxana_asm_server

Remove the intermediate image (without the grid):

docker rm -f asm_grid_build

Optional – Check the New Image

Run the container at the background:

docker run –privileged –detach –name asm_grid -h gridserver -p 1521:1521 -p 2222:22 –shm-size 2048m -e TZ=UTC -v /sys/fs/cgroup:/sys/fs/cgroup:ro –volume /depo:/software –volume /boot:/boot –device=/dev/sdb1 –restart always ynixon/axxana_asm_server

Connect to the new container to verify the environment:

docker exec -it –user grid asm_grid bash -l

Export the image and compress it:

docker save -o /depo/export/docker_axxana_asm_server.tar ynixon/axxana_asm_server:latest

gzip docker_axxana_asm_server.tar

Optional – Load the Image

Copy the file \\nas\shared\oracle_tools\DockerASM\docker_axxana_asm_server.tar.gz to /tmp

Uncompress the file:

gunzip /tmp/docker_axxana_asm_server.tar.gz

Load the file into the local container repository:

docker load -i /depo/export/docker_axxana_asm_server.tar

Run a container based on the loaded image:

docker run –privileged –detach –name asm_grid -h gridserver -p 1521:1521 -p 2222:22 –shm-size 2048m -e TZ=UTC -v /sys/fs/cgroup:/sys/fs/cgroup:ro –volume /boot:/boot –device=/dev/sdb1 –restart always ynixon/axxana_asm_server

Test connection from remote machines:

ssh root@<Black Box IP> -p 2222

sqlplus sys/axxana@<Black Box IP>:1521/+ASM as sysasm

Deploy web interface – Portainer:

$ docker volume create portainer_data

$ docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Open browser at: http://<docker server>:9000/