Install oracle 11g using Docker

Keywords: Oracle Docker Database SQL

  •  2019-07-30
  •  
  •  0
  •  
  •   0

1. Introduction

Oracle Database, also known as Oracle RDBMS, or Oracle for short.Oracle is a relational database management system.

With docker, it is no longer difficult to install oracle, just a few steps.

It is important to note that before referring to this article, you need to have a foundation for working with dockers and how to use dockers can be referenced Here

2. Installation

2.1. Install oracle 11g mirror to docker

2.1.1, Search for qualified mirrors

docker search oracle

NAME                                  DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
oraclelinux                           Official Docker builds of Oracle Linux.         573                 [OK]
jaspeen/oracle-11g                    Docker image for Oracle 11g database            99                                      [OK]
oracle/openjdk                        Docker images containing OpenJDK Oracle Linux   55                                      [OK]
......

2.1.2, Choose to install jaspeen/oracle-11g, wait for download and installation to complete

docker pull jaspeen/oracle-11g

2.1.3, View downloaded images

docker images

REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
jaspeen/oracle-11g         latest              0c8711fe4f0f        3 years ago         281MB

Note that this image does not install oracle directly. It configures the environment and provides installation scripts. We just need to configure the oracle installation directory and start the image as required.

2.2. Preparing oracle 11g installation files

2.2.1, download oracle 11g installation file

from oracle website Download the necessary installation package, here we will oracle 11g For example, download two zip packages, linux.x64_11gR2_database_1of2.zip and linux.x64_11gR2_database_2of2.zip, respectively, and unzip them to the home directory (following directory structure)


  home
    └─database
        ├─doc
        ├─install
        ├─response
        ├─rpm
        ├─sshsetup
        ├─stage
        ├─runInstaller
        └─welcome.html

2.3. Install oracle

2.3.1. Notes

Why unzip the directory structure above? Let's first look at the installation script provided by the jaspeen/oracle-11g image

#!/usr/bin/env bash
set -e
source /assets/colorecho

trap "echo_red '******* ERROR: Something went wrong.'; exit 1" SIGTERM
trap "echo_red '******* Caught SIGINT signal. Stopping...'; exit 2" SIGINT

if [ ! -d "/install/database" ]; then
	echo_red "Installation files not found. Unzip installation files into mounted(/install) folder"
	exit 1
fi

echo_yellow "Installing Oracle Database 11g"

su oracle -c "/install/database/runInstaller -silent -ignorePrereq -waitforcompletion -responseFile /assets/db_install.rsp"
/opt/oracle/oraInventory/orainstRoot.sh
/opt/oracle/app/product/11.2.0/dbhome_1/root.sh

You can see from the script that it reads the / install/database directory and prompts Installation files not found. Unzip installation files into mounted(/install) folder if none exists

2.3.2, Boot Mirror (perform oracle installation)

Interpretation of the command:

  • Command for docker run to start container
  • privileged gives this container privileges. Installing oracle may require manipulation of files or directories that require root privileges
  • Name Give this container a name
  • p map port
  • v Hang file to container specified directory (/home for container /install/database)
  • jaspeen/oracle-11g starts the specified container
docker run --privileged --name oracle11g -p 1521:1521 -v /home:/install jaspeen/oracle-11g

Database is not installed. Installing...
Installing Oracle Database 11g
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB.   Actual 47303 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 1023 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-04-17_08-14-23AM. Please wait ...
You can find the log of this install session at:
 /opt/oracle/oraInventory/logs/installActions2019-04-17_08-14-23AM.log
 ......

This installation process can be lengthy and has a lot of logs, only a few are provided here.Notice that 100% complete prints in the log represent successful oracle installation

2.3.3, Installation complete

Check the running status again, oracle has started and finished

docker ps -a

CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                      PORTS                                                                             NAMES
7f53f07c93e5        jaspeen/oracle-11g   "/assets/entrypoint...."   About an hour ago   Up About an hour            0.0.0.0:1521->1521/tcp, 8080/tcp                                                  oracle11g

2.3.4, other things to note, if the log hasn't been updated for a long time, check that the docker is dead

View the status of the docker

docker ps -a
Error response from daemon: An invalid argument was supplied.

If the prompt above indicates that the docker is dead, we just need to re-execute the installation steps to let the oracle installation complete

ps: Based on my guess, I did not allocate enough resources to the docker, so I turned the memory and cpu of the docker up a bit and oracle finished installing smoothly.

docker rm oracle11g
docker run --privileged --name oracle11g -p 1521:1521 -v oracleinstall:/install jaspeen/oracle-11g

3. Configuration

The default scott user is locked and we need to unlock it to successfully connect to oracle through the database tools

3.1, connect to container,

docker exec -it oracle11g /bin/bash

3.2, switch to oracle user and connect to sql console

[root@7f53f07c93e5 /]# su - oracle
Last login: Wed Apr 17 08:29:31 UTC 2019
[oracle@7f53f07c93e5 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Apr 17 09:29:49 2019

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

3.3, Unlock Account

SQL> alter user scott account unlock;
User altered.
SQL> commit;
Commit complete.
SQL> conn scott/tiger
ERROR:
ORA-28001: the password has expired
Changing password for scott
New password:
Retype new password:
Password changed
Connected.
SQL> 

3.4, Connect to oracle database using dataGrip

After the database installation is complete, use the default sid of orcl, port 1521, scott/tiger to connect

Reference:

  • https://zh.wikipedia.org/wiki/Oracle%E6%95%B0%E6%8D%AE%E5%BA%93
  • https://hub.docker.com/r/jaspeen/oracle-11g
  • https://stackoverflow.com/questions/37468788/what-is-the-right-way-to-add-data-to-an-existing-named-volume-in-docker
  • https://hub.docker.com/_/busybox
  • http://blog.grayidea.cn/archives/67
  • https://blog.csdn.net/u013238950/article/details/5099940

Posted by Xoom3r on Sat, 28 Sep 2019 11:02:39 -0700