OracleDatabaseのDocker Imageが欲しくなったのでソースコードを取得してビルドした。以下はその時の作業ログである。
ソースコードの取得
ソースコードはOracleからダウンロードする。
https://www.oracle.com/jp/database/technologies/oracle-database-software-downloads.html#21c
ダウンロードする際、Oracleのアカウントが必要なので適宜作る。
Docker関連のファイルの取得
Oracle DatabaseのDocker関連のファイルはGithubでホスティングされている。Gitコマンドを使って取得する。
git clone https://github.com/oracle/docker-images oracle-docker-images
Docker Imageのビルド
ダウンロードしたソースコードのzipファイルを oracle-docker-images/OracleDatabase/SingleInstance/dockerfiles/21.3.0 配下に配置する。 zipファイルのまま置けば良い。
oracle-docker-images/OracleDatabase/SingleInstance/dockerfiles/ にカレントディレクトリを移動して buildContainerImage.sh
を用いてイメージをビルドする。
$ cd oracle-docker-images/OracleDatabase/SingleInstance/dockerfiles $ ./buildContainerImage.sh -v 21.3.0 -e -i Checking Docker version. Ignored MD5 checksum. ========================== Container runtime info: Client: Context: default Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc., v0.8.2) compose: Docker Compose (Docker Inc., v2.6.1) extension: Manages Docker extensions (Docker Inc., v0.2.7) sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0) scan: Docker Scan (Docker Inc., v0.17.0) Server: Containers: 1 Running: 1 Paused: 0 Stopped: 0 Images: 35 Server Version: 20.10.17 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 2 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc Default Runtime: runc Init Binary: docker-init containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1 runc version: v1.1.2-0-ga916309 init version: de40ad0 Security Options: seccomp Profile: default cgroupns Kernel Version: 5.10.104-linuxkit Operating System: Docker Desktop OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 5.805GiB Name: docker-desktop ID: ALLO:PR74:3K7B:XJUU:ERHJ:DTS7:NRVE:YXKG:JXFD:KPFZ:3UHY:CYFA Docker Root Dir: /var/lib/docker Debug Mode: false HTTP Proxy: http.docker.internal:3128 HTTPS Proxy: http.docker.internal:3128 No Proxy: hubproxy.docker.internal Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: hubproxy.docker.internal:5000 127.0.0.0/8 Live Restore Enabled: false ========================== Building image 'oracle/database:21.3.0-ee' ... [+] Building 112.8s (8/15) [+] Building 113.0s (8/15) [+] Building 253.8s (10/15) [+] Building 254.0s (10/15) [+] Building 325.6s (10/15) [+] Building 325.8s (10/15) [+] Building 325.9s (10/15) [+] Building 486.9s (16/16) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 5.02kB 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/oraclelinux:7-slim 3.4s => [auth] library/oraclelinux:pull token for registry-1.docker.io 0.0s => [base 1/4] FROM docker.io/library/oraclelinux:7-slim@sha256:0720e77f9f3cfad8d4cb5cea9905f53394bf5f1600517be01d39a0c388c44306 15.8s => => resolve docker.io/library/oraclelinux:7-slim@sha256:0720e77f9f3cfad8d4cb5cea9905f53394bf5f1600517be01d39a0c388c44306 0.0s => => sha256:0720e77f9f3cfad8d4cb5cea9905f53394bf5f1600517be01d39a0c388c44306 547B / 547B 0.0s => => sha256:0c6dd0b0aa41064675488a0c10ebee4ad20b1e79c11369168faef24ecbf56a75 529B / 529B 0.0s => => sha256:779edc935fbd98a3330d10cdb68621899bdd7250ee1dc7b72e31be54a544f2b9 1.48kB / 1.48kB 0.0s => => sha256:d96bccd7291ff1dc9e55f40b596e14900d110382763aa46814bc43ac1b40f57c 49.83MB / 49.83MB 5.0s => => extracting sha256:d96bccd7291ff1dc9e55f40b596e14900d110382763aa46814bc43ac1b40f57c 10.0s => [internal] load build context 103.8s => => transferring context: 3.11GB 103.8s => [base 2/4] COPY setupLinuxEnv.sh checkSpace.sh /opt/install/ 0.2s => [base 3/4] COPY runOracle.sh startDB.sh createDB.sh createObserver.sh dbca.rsp.tmpl setPassword.sh checkDBStatus.sh runUserScripts.sh relinkOracleBinary.sh configTcps. 0.1s => [base 4/4] RUN chmod ug+x /opt/install/*.sh && sync && /opt/install/checkSpace.sh && /opt/install/setupLinuxEnv.sh && rm -rf /opt/install 61.8s => [builder 1/2] COPY --chown=oracle:dba LINUX.X64_213000_db_home.zip db_inst.rsp installDBBinaries.sh /opt/install/ 12.7s => [builder 2/2] RUN chmod ug+x /opt/install/*.sh && sync && /opt/install/installDBBinaries.sh ee 180.3s => [stage-2 1/4] COPY --chown=oracle:dba --from=builder /opt/oracle /opt/oracle 39.5s => [stage-2 2/4] RUN /opt/oracle/oraInventory/orainstRoot.sh && /opt/oracle/product/21c/dbhome_1/root.sh 0.8s => [stage-2 3/4] WORKDIR /home/oracle 0.0s => [stage-2 4/4] RUN echo 'ORACLE_SID=${ORACLE_SID:-ORCLCDB}; export ORACLE_SID=${ORACLE_SID^^}' > .bashrc 0.2s => exporting to image 47.2s => => exporting layers 47.2s => => writing image sha256:079e359c2d74c0ae4f7e6dcab11af529d3af317e892448701b14adf8bd7c1212 0.0s => => naming to docker.io/oracle/database:21.3.0-ee 0.0s Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them Oracle Database container image for 'ee' version 21.3.0 is ready to be extended: --> oracle/database:21.3.0-ee Build completed in 488 seconds.
ビルドが完了すると巨大なDocker Imageが出来上がる。
oracle/database 21.3.0-ee 079e359c2d74 23 minutes ago 7.94GB
起動方法
必要な環境変数を.envとして用意しておく。パスワードは暫定的に testing1234
を用いるようにした。
次のDockerコマンドで起動できる。データ保存用のVolumeは oracle-db-data
という名前で用意した。
接続方法
sqlplusを用いて接続する。sqlplusはどのように準備をしてもよいが、今回は手順の省略のためコンテナ内部のsqlplusを使用する。
$ docker exec -it oracle bash
接続文字列をCONNECTコマンドに渡すことで接続できる。
bash-4.2$ sqlplus /nolog SQL*Plus: Release 21.0.0.0.0 - Production on Wed Nov 30 23:59:08 2022 Version 21.3.0.0.0 Copyright (c) 1982, 2021, Oracle. All rights reserved. SQL> connect sys/testing1234@localhost:1521/ORCLCDB as sysdba Connected.
SQL> alter session set container=ORCLPDB1; Session altered. SQL> create user developer identified by developer; User created. SQL> grant create session to developer; Grant succeeded.
参考
- https://qiita.com/niwasawa/items/0834e77b0690a5c8501d
- https://cosol.jp/techdb/2019/05/use_oracle_database_no_charge/
- https://docs.oracle.com/cd/E16338_01/datamine.112/e57718/connecting.htm
- https://docs.oracle.com/cd/E16338_01/appdev.112/b56265/tdddg_connecting.htm
- https://products.sint.co.jp/siob/blog/oracle-access
- https://style.potepan.com/articles/22992.html
- https://www.climb.co.jp/blog_dbmoto/archives/268
- https://souiunogaii.hatenablog.com/entry/Oracle-PDB