Fork me on GitHub
Suzf  Blog

How-to run Oracle 12.2 with docker on Ubuntu

License: Attribution-NonCommercial-ShareAlike 4.0 International

本文出自 Suzf Blog。 如未注明,均为 SUZF.NET 原创。

转载请注明:http://suzf.net/post/1436

前言

昨天有一位搞 DBA 同学问我会不会用 Docker。Ta 想要在上面跑一个 Oracle 实例。整个过程非常流畅,写篇文章备用。 :)


ENV
# lsb_release -a
Distributor ID: Ubuntu
Description:  Ubuntu 16.04.2 LTS
Release:  16.04
Codename: xenial
 
# Oracle Version Package
linuxx64_12201_database.zip


Install docker

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install docker-engine -y
Download Oracle Docker Image

Docker Images from Oracle https://github.com/oracle/docker-images


cd ~
git clone [email protected]:oracle/docker-images.git  oracle-images
Download & Upload Oracle

Download page http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

when you download the package, upload it to the ${docker-images}/OracleDatabase/dockerfiles/x.x.x.x/


du -sh ./oracle-images/OracleDatabase/dockerfiles/12.2.0.1/* | grep zip
3.3G    ./oracle-images/OracleDatabase/dockerfiles/12.2.0.1/linuxx64_12201_database.zip


接下来,开始无脑安装。因为有一些依赖包需要安装,请确保 REPO & 网络可用。

Build Docker Image

# bash oracle-images/OracleDatabase/dockerfiles/buildDockerImage.sh -v 12.2.0.1 -e
# bash oracle-images/OracleDatabase/dockerfiles/buildDockerImage.sh
Usage: buildDockerImage.sh -v [version] [-e | -s | -x] [-i]
Builds a Docker Image for Oracle Database.
 
Parameters:
   -v: version to build
       Choose one of: oracle-images  
   -e: creates image based on 'Enterprise Edition'
   -s: creates image based on 'Standard Edition 2'
   -x: creates image based on 'Express Edition'
   -i: ignores the MD5 checksums
 
* select one edition only: -e, -s, or -x
 
LICENSE CDDL 1.0 + GPL 2.0
 
Copyright (c) 2014-2017 Oracle and/or its affiliates. All rights reserved.


整个过程分16步自动完成,具体完成时间取决于系统环境配置。

成功的日志类似如下的:
Oracle Database Docker Image for 'ee' version 12.2.0.1 is ready to be extended:
 
--> oracle/database:12.2.0.1-ee
 
build completed in 50235 second


Check Image

$sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
oracle/database     12.2.0.1-ee         2b8746d2b5a0        23 hours ago        14.8GB
oraclelinux         7-slim              0b44f4e6980d        13 days ago         114MB

Run Oracle

docker run --name oracle
-p 1521:1521
-p 5500:5500
-v /opt/oracle/oradata:/opt/oracle/oradata
oracle/database:12.2.0.1-ee
 
 
##########################################
docker run --name <container name> \
-p <host port>:1521 -p <host port>:5500 \
-e ORACLE_SID=<your SID> \
-e ORACLE_PDB=<your PDB name> \
-e ORACLE_PWD=<your database passwords> \
-e ORACLE_CHARACTERSET=<your character set> \
-v [<host mount point>:]/opt/oracle/oradata \
oracle/database:12.2.0.1-ee
 
Parameters:
   --name:        The name of the container (default: auto generated)
   -p:            The port mapping of the host port to the container port.
                  Two ports are exposed: 1521 (Oracle Listener), 5500 (OEM Express)
   -e ORACLE_SID: The Oracle Database SID that should be used (default: ORCLCDB)
   -e ORACLE_PDB: The Oracle Database PDB name that should be used (default: ORCLPDB1)
   -e ORACLE_PWD: The Oracle Database SYS, SYSTEM and PDB_ADMIN password (default: auto generated)
   -e ORACLE_CHARACTERSET:
                  The character set to use when creating the database (default: AL32UTF8)
   -v             The data volume to use for the database.
                  Has to be owned by the Unix user "oracle" or set appropriately.
                  If omitted the database will not be persisted over container recreation.
Changing the admin accounts passwords


# ./OracleDatabase/dockerfiles/12.2.0.1/setPassword.sh
docker exec <container name> ./setPassword.sh <your password>

更多信息 详见 https://github.com/oracle/docker-images/tree/master/OracleDatabase

$sudo docker ps
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                                            NAMES
aba4fc65f3e7        oracle/database:12.2.0.1-ee   "/bin/sh -c 'exec ..."   7 hours ago         Up 2 hours          0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp   oracle

Oracle SQL Developer Test

至此,一个基于 Docker 的简单测试环境构建完成。

~ EOF ~

Reference

[0] https://github.com/oracle/docker-images

[1] https://github.com/oracle/docker-images/tree/master/OracleDatabase

「一键投喂 软糖/蛋糕/布丁/牛奶/冰阔乐!」

Suzf Blog

(๑>ڡ<)☆ 谢谢 ~

使用微信扫描二维码完成支付