Posted in 2016

Docker with 12c SE2, step by step

Hi all,
maybe you are interrested in docker or you want to learn new things like me, I have created a docker guide to a point where you can tnsping the listener. To create a database would be just uninterresting. Everything is in the documentation too, but there is always someone who wants it faster. So you will find it there too.. serv-1 is my virtualbox machine for hosting the containers which I call host-[1,2,3] in this text. I have downloaded 12c SE2 zip files and stored them in /software in serv-1.

  1. find a device for btrfs
    [root@serv-1 ~]# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 30G 0 disk
    ├─sda1 8:1 0 500M 0 part /boot
    └─sda2 8:2 0 29.5G 0 part
    ├─ol-root 251:0 0 28.5G 0 lvm /
    └─ol-swap 251:1 0 1G 0 lvm [SWAP]
    sdb 8:16 0 50G 0 disk
    sr0 11:0 1 1024M 0 rom
    

  2. create a btrfs on a disk
    [root@serv-1 ~]# mkfs.btrfs /dev/sdb -f
    

  3. define a target to mount btrfs

    [root@serv-1 ~]# cat /etc/systemd/system/var-lib-docker.mount
    [Unit]
    Description = Docker Image Store
    
    [Mount]
    What = UUID=b1d40d65-f3c8-4774-9b70-ac3a73d49339
    Where = /var/lib/docker
    Type = btrfs
    
    [Install]
    WantedBy = multi-user.target
    
    [root@serv-1 ~]# systemctl enable var-lib-docker.mount
    [root@serv-1 ~]# systemctl start var-lib-docker.mount
    

  4. Install the docker engine

    [root@serv-1 ~]# yum install docker-engine
    Installed:
    docker-engine.x86_64 0:1.12.2-1.0.1.el7
    

  5. Filesystem starts first
    [root@serv-1 docker]# cat /etc/systemd/system/docker.service.d/var-lib-docker-mount.conf
    [Unit]
    Requires=var-lib-docker.mount
    After=var-lib-docker.mount
    
  6. Start docker

    [root@serv-1 ~]# systemctl start docker
    [root@serv-1 ~]# systemctl enable docker
    Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to
    /usr/lib/systemd/system/docker.service.
    

  7. Pull an oraclelinux image

    [root@serv-1 ~]# docker pull oraclelinux:7
    

  8. Now you can start a container

    [root@serv-1 ~]# docker run -i -t -d --name guest1 --restart=always oraclelinux:7
    

  9. To login you can either “docker attach” or “docker exec”, I learned that exec is better with starting a container with -d

    [root@serv-1 ~]# docker exec -i -t guest1 /bin/bash
    

  10. Preparing the docker image (oraclelinux) for Oracle software, for this I created a script and mount a readonly directory to the container

    [root@serv-1 software]# pwd
    /software
    [root@serv-1 software]# cat define_oracle.sh
    export http_proxy=http://172.X.X.X:8080
    echo "Preparing environment..."
    mkdir -p /products/oracle/install && \
    groupadd dba && \
    useradd -g dba -d /home/oracle -m -s /bin/bash oracle && \
    echo oracle:oracle | chpasswd
    sleep 2
    echo "Installing necessary packages..."
    yum -y install unzip tar openssl wget binutils.x86_64 \
    compat-libcap1.x86_64 \
    compat-libstdc++-33.i686 \
    compat-libstdc++-33.x86_64 \
    gcc.x86_64 \
    gcc-c++.x86_64 \
    glibc.i686 \
    glibc.x86_64 \
    glibc-devel.i686 \
    glibc-devel.x86_64 \
    ksh \
    libaio.i686 \
    libaio.x86_64 \
    libaio-devel.i686 \
    libaio-devel.x86_64 \
    libgcc.i686 \
    libgcc.x86_64 \
    libstdc++.i686 \
    libstdc++.x86_64 \
    libstdc++-devel.i686 \
    libstdc++-devel.x86_64 \
    libXi.i686 \
    libXi.x86_64 \
    libXtst.i686 \
    libXtst.x86_64 \
    make.x86_64 \
    sysstat.x86_64 | tee -a /tmp/install_packages.log > /dev/null 2>&1
    
    yum clean all > /dev/null 2>&1
    mkdir /products/oracle/oradata
    unzip -d /products/oracle/install/ /media/software/linuxamd64_12102_database_se2_1of2.zip | tee -a /tmp/unzip.log > /dev/null 2>&1
    
    unzip -d /products/oracle/install/ /media/software/linuxamd64_12102_database_se2_2of2.zip | tee -a /tmp/unzip.log > /dev/null 2>&1
    
    chown -R oracle:dba /products
    echo "Preparation finished..."
    

With this command I mount the /software directory with the oracle zip files and my script

[root@serv-1 software]# docker run -i -t --hostname host-01 --name guest1 --restart=always --shm-size 1GB -v /software/:/media/software:ro oraclelinux:7
[root@host-01 /]#
[root@host-01 /]# /media/software/define_oracle.sh
Preparing environment...
Installing necessary packages...
Preparation finished...
[oracle@host-01 /]$ cd /products/oracle/install/database/response
  1. Here you are already in the part where you can define the response file for the installation, once you modified it, you can run the installation
    [oracle@host-01 database]$ ./runInstaller -silent -responseFile
    /products/oracle/install/database/response/db_install.rsp -ignorePrereq
    Starting Oracle Universal Installer...
    Checking Temp space: must be greater than 500 MB. Actual 45844 MB Passed
    Checking swap space: must be greater than 150 MB. Actual 964 MB Passed
    
    Preparing to launch Oracle Universal Installer from /tmp/OraInstall2016-12-30_12-27-32PM. Please
    wait ...[oracle@host-01 database]$ [WARNING] [INS-32055] The Central Inventory is located in the
    Oracle base.
    
    ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory.
    
    You can find the log of this install session at:
    
    /products/oracle/oraInventory/logs/installActions2016-12-30_12-27-32PM.log
    
    The installation of Oracle Database 12c was successful.
    Please check '/products/oracle/oraInventory/logs/silentInstall2016-12-30_12-27-32PM.log' for more details.
    
    As a root user, execute the following script(s):
    1. /products/oracle/oraInventory/orainstRoot.sh
    2. /products/oracle/dbhome/12.1.0.2/root.sh
    
    Successfully Setup Software.
    [oracle@host-01 database]$ exit
    exit
    [root@host-01 /]# /products/oracle/oraInventory/orainstRoot.sh
    Changing permissions of /products/oracle/oraInventory.
    Adding read,write permissions for group.
    Removing read,write,execute permissions for world.
    Changing groupname of /products/oracle/oraInventory to dba.
    The execution of the script is complete.
    
    [root@host-01 /]# /products/oracle/dbhome/12.1.0.2/root.sh
    Check /products/oracle/dbhome/12.1.0.2/install/root_host-01_2016-12-30_12-35-10.log for the
    output of root script
    
  2. Remove the installation files so your image is not big

    [root@host-01 /]# cd /products/oracle/install/
    [root@host-01 install]# ll
    total 0
    drwxr-xr-x 1 oracle dba 110 Jul 6 2015 database
    [root@host-01 install]# rm -rf database/
    [root@host-01 install]#
    
  3. Login to the serv-1 and stop the container

    login as: root
    root@192.168.56.102's password:
    Last login: Fri Dec 30 07:29:54 2016 from 192.168.56.1
    [root@serv-1 ~]# docker stop guest1
    guest1
    [root@serv-1 ~]#
  4. Create your image, this takes time..

    [root@serv-1 ~]# docker commit -m "Oracle 12c SE2" -a "Peter Sorger" `docker ps -l -q` oracledb12c/se2:v1.0
    
  5. Create your first host for the database, I define the port mapping (serv-1:host-1)

    [root@serv-1 ~]# docker run -i -t -d --hostname host-01 --name guest1 --restart=always --shm-size 1GB 
    -p 1521:1521 oracledb12c/se2:v1.0
  6. Login and start the listener, int this step you could create the database too, but that’s another story or even create the database, define everything, commit and deploy, as you want

    [root@serv-1 ~]# docker exec -it guest1 /bin/bash
    [root@host-01 /]# su oracle
    [oracle@host-01 /]$ . oraenv
    ORACLE_SID = [oracle] ?
    ORACLE_HOME = [/home/oracle] ? /products/oracle/dbhome/12.1.0.2
    The Oracle base has been set to /products/oracle
    [oracle@host-01 /]$ lsnrctl start
    LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 30-DEC-2016 12:59:21
    Starting /products/oracle/dbhome/12.1.0.2/bin/tnslsnr: please wait...
    TNSLSNR for Linux: Version 12.1.0.2.0 - Production
    
    Log messages written to /products/oracle/diag/tnslsnr/host-01/listener/alert/log.xml
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host-01)(PORT=1521)))
    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
    STATUS of the LISTENER
    ------------------------
    Alias LISTENER
    Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
    Start Date 30-DEC-2016 12:59:21
    Uptime 0 days 0 hr. 0 min. 0 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Listener Log File /products/oracle/diag/tnslsnr/host-01/listener/alert/log.xml
    
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host-01)(PORT=1521)))
    The listener supports no services
    The command completed successfully
    [oracle@host-01 /]$ exit
    [root@host-01 /]# exit 
  7. Install a client or any application that can connect to the listener or database if you created it. I have installed a client.

    [oracle@serv-1 client]$ ./runInstaller -silent -responseFile /software/client/response/client_install.rsp -ignorePrereq
    
    You can find the log of this install session at:
    /products/oracle/oraInventory/logs/installActions2016-12-30_08-43-47AM.log
    The installation of Oracle Client 12c was successful.
    
    Please check '/products/oracle/oraInventory/logs/silentInstall2016-12-30_08-43-47AM.log' for more details.
    
    As a root user, execute the following script(s):
    1. /products/oracle/oraInventory/orainstRoot.sh
    Successfully Setup Software.
    [oracle@serv-1 client]$ exit
    [root@serv-1 client]# /products/oracle/oraInventory/orainstRoot.sh
    Changing permissions of /products/oracle/oraInventory.
    Adding read,write permissions for group.
    Removing read,write,execute permissions for world.
    Changing groupname of /products/oracle/oraInventory to dba.
    The execution of the script is complete. 
  8. Connect to the database

    [root@serv-1 client]# su oracle
    [oracle@serv-1 client]$ export ORACLE_HOME=/products/oracle/client
    [oracle@serv-1 client]$ export LD_LIBRARY_PATH=/products/oracle/client/lib
    [oracle@serv-1 client]$ export PATH=$PATH:/products/oracle/client/bin
    [oracle@serv-1 client]$ tnsping localhost:1521/test
    
    TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 30-DEC-2016 08:47:54
    Copyright (c) 1997, 2014, Oracle. All rights reserved.
    
    Used parameter files:
    Used HOSTNAME adapter to resolve the alias
    
    Attempting to contact
    (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=test))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))
    OK (370 msec)
    

And now you can work with your database in a container.

Advertisements

Author:

Database administrator who loves to work with Oracle software. (Sometimes not)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s