登入docker商店獲取Oracle Database和Weblogic的映象

$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: code501
Password: 
如果出現:Login Succeeded則登入成功
如果出現:Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password(失敗)

解決方法:

2. Pull database-enterprise Images

# docker pull 10.128.222.245:5000/database-enterprise:12.2.0.2

下載成功:

#docker pull 10.128.222.245:5000/database-enterprise:12.2.0.2 12.2.0.2: Pulling from database-enterprise Digest: sha256:4a6ce8480d5e0aa0dd798564a5340fbfc45033a26468745482457d92008195a1 Status: Downloaded newer image for 10.128.222.245:5000/database-enterprise:12.2.0.2

3. 執行Oracle資料庫容器

使用docker run命令執行容器,-p引數是將容器埠對映到外部,--name 指定容器的名稱。指定容器名稱可以通過該名稱引用該容器,而不是通過它隨機生成的id。

檢視本地映象

$ docker images
  • 建立配置檔案db_env.dat,該配置檔案可以定義資料庫名,密碼,域和擴充套件包
####################################################################
## Copyright(c) Oracle Corporation 1998,2016. All rights reserved.##
##                                                                ##
##                   Docker OL7 db12c dat file                    ##
##                                                                ##
####################################################################

##------------------------------------------------------------------
## Specify the basic DB parameters
##------------------------------------------------------------------

## db sid (name)
## default : ORCL
## cannot be longer than 8 characters

DB_SID=OraDoc

## db passwd
## default : Oracle

DB_PASSWD=LetsDocker

## db domain
## default : localdomain

DB_DOMAIN=my.domain.com

## db bundle
## default : basic
## valid : basic / high / extreme 
## (high and extreme are only available for enterprise edition)

DB_BUNDLE=basic

## end
  • 建立容器
$ docker run -d --env-file ./db_env.dat -p 1527:1521 -p 5507:5500 -it --name dockerDB --shm-size="8g" store/oracle/database-enterprise:12.1.0.2

注:

$ docker run -d --env-file <path_to_env_file> -p <listener_port>:1521 -p <http_port>:5500 -it --name <container_name> --shm-size="<shared_memory_size>" <image_name>

Parameters:
   <path_to_env_file> is the path to the environment file you created using above example. 
   <listener_port> is the port on host machine to map the container's 1521 port (listener port).
   <http_port> is the port on host machine to map the container's 5500 port (http service port).
   <container_name> is the container name you want to create.
   <shared_memory_size> is the memory size for the container to run. The minimum requirement is 4GB (--shm-size="4g").
   <image_name> is the image that you use to create a container.

進入容器:

$ docker exec -it <container_name> /bin/bash
  • 日誌:

第一次構建資料庫大約需要5至8分鐘,日誌儲存在容器內的/home/oracle/setup/log檔案中 檢查資料庫設定是否成功,檢查日誌檔案“ /home/oracle/setup/log/setupDB.log”。如果顯示“is shown, the database setup was successful.”,則資料庫安裝成功。啟動日誌“/home/oracle/setup/log/startupDB.log”

新建setPassword.sh檔案

#!/bin/bash
# LICENSE CDDL 1.0 + GPL 2.0
#
# Copyright (c) 1982-2016 Oracle and/or its affiliates. All rights reserved.
# 
# Since: November, 2016
# Author: [email protected]
# Description: Sets the password for sys, system and pdb_admin
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
# 

ORACLE_PWD=$1
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`"
ORAENV_ASK=NO
source oraenv

sqlplus / as sysdba << EOF
      ALTER USER SYS IDENTIFIED BY "$ORACLE_PWD";
      ALTER USER SYSTEM IDENTIFIED BY "$ORACLE_PWD";
      ALTER SESSION SET CONTAINER=$ORACLE_PDB;
      ALTER USER PDBADMIN IDENTIFIED BY "$ORACLE_PWD";
      exit;
EOF

例:將密碼更改為:LetsDocker

$ docker exec my_db ./setPassword.sh LetsDocker

Weblogic

1、從私有倉庫下載weblogic的Docker映象和擴充套件包

webloggic映象已經從docker商店下載並上傳到了私有倉庫(10.128.222.245)中

$ docker pull 10.128.222.245:5000/store/oracle/weblogic:12.2.1.2

2、編輯"12212-oradb-medrec/container-scripts/oracledatabase.properties"檔案

設定Oracle Thin XA驅動程式,資料庫URL,使用者和密碼以連線到我們之前建立的Oracle資料庫容器

domainname=medrec
domainhome=/u01/oracle/wlserver/samples/domains/medrec
admin_name=MedRecServer
dsname=MedRecGlobalDataSourceXA
dsdbname=ORCLCDB
dsjndiname=jdbc/MedRecGlobalDataSourceXA
dsdriver=oracle.jdbc.xa.client.OracleXADataSource
dsurl=jdbc:oracle:thin:@//OracleDatbaseIP:1521/ORCLCDB
dsusername=system
dspassword=LetsDocker
dstestquery=SELECT * FROM DUAL
dsmaxcapacity=1

2、編輯"12212-oradb-medrec"資料夾下的Dockerfile檔案

執行Docker images命令檢視本地映象的weblogic的REPOSITORY

docker images
REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE

10.128.222.245:5000/store/oracle/weblogic              12.2.1.2            0f56fc2fbf56        3 weeks ago         1.12 GB
10.128.222.245:5000/store/oracle/database-enterprise   12.1.0.2            9410a79c6531        3 weeks ago         5.27 GB

編輯Dockerfile並將FROM行改為:10.128.222.245:5000/store/oracle/weblogic

3、構建"12212-oradb-medrec"映象

進入"12212-oradb-medrec"資料夾,並執行:

$ docker build -t 12212-oradb-medrec . 

映象構建完成後使用docker images檢視本地映象,會發現多了一個"12212-oradb-medrec"映象

REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE
12212-oradb-medrec                                     latest              f32f0488dffd        6 hours ago         1.5 GB
10.128.222.245:5000/store/oracle/weblogic              12.2.1.2            0f56fc2fbf56        3 weeks ago         1.12 GB
10.128.222.245:5000/store/oracle/database-enterprise   12.1.0.2            9410a79c6531        3 weeks ago         5.27 GB

4、建立並執行MedRec Docker容器

$ docker run -d -it -p 7011:7011 12212-oradb-medrec

檢視執行進度並獲取容器的IP地址

$ docker logs -f <container id> 

通過http://10.128.222.247:7011/console,來驗證Oracle database。

賬號:weblogic
密碼:welcome1

驗證Weblogic應用

地址:http://10.128.222.247:7011/medrec/
.