├── .gitattributes ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── docs ├── apex-install.md └── docker-dev.md ├── files ├── .gitkeep └── apex-install.sql └── scripts ├── checkDBStatus.sh ├── enableEmRemoteAccess.sh ├── runOracle.sh └── shutdownDb.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | ## GITATTRIBUTES FOR WEB PROJECTS 2 | # 3 | # These settings are for any web project. 4 | # 5 | # Details per file setting: 6 | # text These files should be normalized (i.e. convert CRLF to LF). 7 | # binary These files are binary and should be left untouched. 8 | # 9 | # Note that binary is a macro for -text -diff. 10 | ###################################################################### 11 | 12 | ## AUTO-DETECT 13 | ## Handle line endings automatically for files detected as 14 | ## text and leave all files detected as binary untouched. 15 | ## This will handle all files NOT defined below. 16 | * text=auto 17 | 18 | ## SOURCE CODE 19 | *.bat text eol=crlf 20 | *.coffee text 21 | *.css text 22 | *.htm text diff=html 23 | *.html text diff=html 24 | *.inc text 25 | *.ini text 26 | *.js text 27 | *.json text 28 | *.jsx text 29 | *.less text 30 | *.od text 31 | *.onlydata text 32 | *.php text diff=php 33 | *.pl text 34 | *.py text diff=python 35 | *.rb text diff=ruby 36 | *.sass text 37 | *.scm text 38 | *.scss text 39 | *.sh text eol=lf 40 | *.sql text 41 | *.styl text 42 | *.tag text 43 | *.ts text 44 | *.tsx text 45 | *.vue text 46 | *.xml text 47 | *.xhtml text diff=html 48 | 49 | ## DOCKER 50 | *.dockerignore text 51 | Dockerfile text 52 | 53 | ## DOCUMENTATION 54 | *.ipynb text 55 | *.markdown text 56 | *.md text 57 | *.mdwn text 58 | *.mdown text 59 | *.mkd text 60 | *.mkdn text 61 | *.mdtxt text 62 | *.mdtext text 63 | *.txt text 64 | AUTHORS text 65 | CHANGELOG text 66 | CHANGES text 67 | CONTRIBUTING text 68 | COPYING text 69 | copyright text 70 | *COPYRIGHT* text 71 | INSTALL text 72 | license text 73 | LICENSE text 74 | NEWS text 75 | readme text 76 | *README* text 77 | TODO text 78 | 79 | ## TEMPLATES 80 | *.dot text 81 | *.ejs text 82 | *.haml text 83 | *.handlebars text 84 | *.hbs text 85 | *.hbt text 86 | *.jade text 87 | *.latte text 88 | *.mustache text 89 | *.njk text 90 | *.phtml text 91 | *.tmpl text 92 | *.tpl text 93 | *.twig text 94 | 95 | ## LINTERS 96 | .csslintrc text 97 | .eslintrc text 98 | .htmlhintrc text 99 | .jscsrc text 100 | .jshintrc text 101 | .jshintignore text 102 | .stylelintrc text 103 | 104 | ## CONFIGS 105 | *.bowerrc text 106 | *.cnf text 107 | *.conf text 108 | *.config text 109 | .babelrc text 110 | .browserslistrc text 111 | .editorconfig text 112 | .env text 113 | .gitattributes text 114 | .gitconfig text 115 | .gitignore text 116 | .htaccess text 117 | *.lock text 118 | *.npmignore text 119 | *.yaml text 120 | *.yml text 121 | browserslist text 122 | Makefile text 123 | makefile text 124 | 125 | ## HEROKU 126 | Procfile text 127 | .slugignore text 128 | 129 | ## GRAPHICS 130 | *.ai binary 131 | *.bmp binary 132 | *.eps binary 133 | *.gif binary 134 | *.ico binary 135 | *.jng binary 136 | *.jp2 binary 137 | *.jpg binary 138 | *.jpeg binary 139 | *.jpx binary 140 | *.jxr binary 141 | *.pdf binary 142 | *.png binary 143 | *.psb binary 144 | *.psd binary 145 | *.svg text 146 | *.svgz binary 147 | *.tif binary 148 | *.tiff binary 149 | *.wbmp binary 150 | *.webp binary 151 | 152 | ## AUDIO 153 | *.kar binary 154 | *.m4a binary 155 | *.mid binary 156 | *.midi binary 157 | *.mp3 binary 158 | *.ogg binary 159 | *.ra binary 160 | 161 | ## VIDEO 162 | *.3gpp binary 163 | *.3gp binary 164 | *.as binary 165 | *.asf binary 166 | *.asx binary 167 | *.fla binary 168 | *.flv binary 169 | *.m4v binary 170 | *.mng binary 171 | *.mov binary 172 | *.mp4 binary 173 | *.mpeg binary 174 | *.mpg binary 175 | *.ogv binary 176 | *.swc binary 177 | *.swf binary 178 | *.webm binary 179 | 180 | ## ARCHIVES 181 | *.7z binary 182 | *.gz binary 183 | *.jar binary 184 | *.rar binary 185 | *.tar binary 186 | *.zip binary 187 | 188 | ## FONTS 189 | *.ttf binary 190 | *.eot binary 191 | *.otf binary 192 | *.woff binary 193 | *.woff2 binary 194 | 195 | ## EXECUTABLES 196 | *.exe binary 197 | *.pyc binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/osx,macos,linux,windows 3 | 4 | ### Linux ### 5 | *~ 6 | 7 | # temporary files which can be created if a process still has a handle open of a deleted file 8 | .fuse_hidden* 9 | 10 | # KDE directory preferences 11 | .directory 12 | 13 | # Linux trash folder which might appear on any partition or disk 14 | .Trash-* 15 | 16 | # .nfs files are created when an open file is removed but is still being accessed 17 | .nfs* 18 | 19 | ### macOS ### 20 | # General 21 | .DS_Store 22 | .AppleDouble 23 | .LSOverride 24 | 25 | # Icon must end with two \r 26 | Icon 27 | 28 | # Thumbnails 29 | ._* 30 | 31 | # Files that might appear in the root of a volume 32 | .DocumentRevisions-V100 33 | .fseventsd 34 | .Spotlight-V100 35 | .TemporaryItems 36 | .Trashes 37 | .VolumeIcon.icns 38 | .com.apple.timemachine.donotpresent 39 | 40 | # Directories potentially created on remote AFP share 41 | .AppleDB 42 | .AppleDesktop 43 | Network Trash Folder 44 | Temporary Items 45 | .apdisk 46 | 47 | ### OSX ### 48 | # General 49 | 50 | # Icon must end with two \r 51 | 52 | # Thumbnails 53 | 54 | # Files that might appear in the root of a volume 55 | 56 | # Directories potentially created on remote AFP share 57 | 58 | ### Windows ### 59 | # Windows thumbnail cache files 60 | Thumbs.db 61 | ehthumbs.db 62 | ehthumbs_vista.db 63 | 64 | # Dump file 65 | *.stackdump 66 | 67 | # Folder config file 68 | [Dd]esktop.ini 69 | 70 | # Recycle Bin used on file shares 71 | $RECYCLE.BIN/ 72 | 73 | # Windows Installer files 74 | *.cab 75 | *.msi 76 | *.msix 77 | *.msm 78 | *.msp 79 | 80 | # Windows shortcuts 81 | *.lnk 82 | 83 | 84 | # End of https://www.gitignore.io/api/osx,macos,linux,windows 85 | 86 | # Files 87 | *.rpm 88 | *.zip 89 | tmp -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM oraclelinux:7-slim 2 | LABEL MAINTAINER="Adrian Png " 3 | 4 | ENV \ 5 | # The only environment variable that should be changed! 6 | ORACLE_PASSWORD=Oracle18 \ 7 | EM_GLOBAL_ACCESS_YN=Y \ 8 | # DO NOT CHANGE 9 | ORACLE_DOCKER_INSTALL=true \ 10 | ORACLE_SID=XE \ 11 | ORACLE_BASE=/opt/oracle \ 12 | ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE \ 13 | ORAENV_ASK=NO \ 14 | RUN_FILE=runOracle.sh \ 15 | SHUTDOWN_FILE=shutdownDb.sh \ 16 | EM_REMOTE_ACCESS=enableEmRemoteAccess.sh \ 17 | EM_RESTORE=reconfigureEm.sh \ 18 | ORACLE_XE_RPM=oracle-database-xe-18c-1.0-1.x86_64.rpm \ 19 | CHECK_DB_FILE=checkDBStatus.sh 20 | 21 | COPY ./files/${ORACLE_XE_RPM} /tmp/ 22 | 23 | RUN yum install -y oracle-database-preinstall-18c && \ 24 | yum install -y /tmp/${ORACLE_XE_RPM} && \ 25 | rm -rf /tmp/${ORACLE_XE_RPM} 26 | 27 | COPY ./scripts/*.sh ${ORACLE_BASE}/scripts/ 28 | 29 | RUN chmod a+x ${ORACLE_BASE}/scripts/*.sh 30 | 31 | # 1521: Oracle listener 32 | # 5500: Oracle Enterprise Manager (EM) Express listener. 33 | EXPOSE 1521 5500 34 | 35 | VOLUME [ "${ORACLE_BASE}/oradata" ] 36 | 37 | HEALTHCHECK --interval=1m --start-period=2m --retries=10 \ 38 | CMD "$ORACLE_BASE/scripts/$CHECK_DB_FILE" 39 | 40 | CMD exec ${ORACLE_BASE}/scripts/${RUN_FILE} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Adrian Png 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker build for Oracle Database 18c Express Edition (XE) 2 | 3 | > **IMPORTANT** 4 | 5 | > This project is now obsolete with the release of version 21c. I have a temporary project to support the new release that you can find [here](https://github.com/fuzziebrain/docker-oracledb21c-xe). This is based on the [official Docker files](https://github.com/oracle/docker-images/tree/main/OracleDatabase/SingleInstance) from Oracle. I strongly recommend tracking the latter. 6 | > 7 | > I would like to take the opportunity to thank everyone who has contributed, and for your interest in this project. 8 | 9 | 10 | 11 | - [Prerequisites](#prerequisites) 12 | - [Build Image](#build-image) 13 | - [Run Container](#run-container) 14 | - [Container Commands](#container-commands) 15 | - [Other](#other) 16 | - [SQL](#sql) 17 | - [APEX Install](#apex-install) 18 | - [SSH into Container](#ssh-into-container) 19 | - [OEM](#oem) 20 | - [Creating a PDB](#creating-a-pdb) 21 | - [`emp` and `dept` tables](#emp-and-dept-tables) 22 | - [Preserving `/opt/oracle/oradata` for Multiple Copies](#preserving-optoracleoradata-for-multiple-copies) 23 | - [Docker Developers](#docker-developers) 24 | 25 | 26 | 27 | ## Prerequisites 28 | 29 | 1. [Download](https://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html) the RPM from Oracle Technology Network and save to folder. We will assume it is in `~/Downloads/oracle-database-xe-18c-1.0-1.x86_64.rpm`. 30 | 31 | 1. _Optional:_ Setup docker network: `docker network create oracle_network`. This is useful if you want other containers to connect to your database (ORDS for example). You can change `oracle_network` for any name you want, however this name will be used in all the code snippets below. 32 | 33 | 1. _Optional:_ Create a folder `mkdir ~/docker/oracle-xe` which will store your Oracle XE data to be preserved after the container is destroyed. 34 | 35 | ## Build Image 36 | 37 | ```bash 38 | -- Clone repo 39 | git clone git@github.com:fuzziebrain/docker-oracle-xe.git 40 | 41 | -- Set the working directory to the project folder 42 | cd docker-oracle-xe 43 | 44 | -- Copy the RPM to docker-odb18c-xe/files 45 | cp ~/Downloads/oracle-database-xe-18c-1.0-1.x86_64.rpm files/ 46 | 47 | -- Build Image 48 | docker build -t oracle-xe:18c . 49 | ``` 50 | 51 | ## Run Container 52 | 53 | _Note first time will take a a while to run for as the `oracle-xe configure` script needs to complete_ 54 | 55 | ```bash 56 | docker run -d \ 57 | -p 32118:1521 \ 58 | -p 35518:5500 \ 59 | --name=oracle-xe \ 60 | --volume ~/docker/oracle-xe:/opt/oracle/oradata \ 61 | --network=oracle_network \ 62 | oracle-xe:18c 63 | 64 | # As this takes a long time to run you can keep track of the initial installation by running: 65 | docker logs oracle-xe 66 | ``` 67 | 68 | Run parameters: 69 | 70 | Name | Required | Description 71 | --- | --- | --- 72 | `-p 1521`| Required | TNS Listener. `32118:1521` maps `32118` on your laptop to `1521` on the container. 73 | `-p 5500`| Optional | Enterprise Manager (EM) Express. `35518:5500` maps `35518` to your laptop to `5500` on the container. You can then access EM via https://localhost:35518/em 74 | `--name` | Optional | Name of container. Optional but recommended 75 | `--volume /opt/oracle/oradata` | Optional | (recommended) If provided, data files will be stored here. If the container is destroyed can easily rebuild container using the data files. 76 | `--network` | Optional | If other containers need to connect to this one (ex: [ORDS](https://github.com/martindsouza/docker-ords)) then they should all be on the same docker network. 77 | `oracle-xe:18c` | Required | This is the `name:tag` of the docker image that was built in the previous step 78 | 79 | ## Container Commands 80 | 81 | ```bash 82 | # Status: 83 | # Look under the STATUS column for "(health: ...". 84 | docker ps 85 | 86 | # Start container 87 | docker start oracle-xe 88 | 89 | # Stop container 90 | docker stop -t 200 oracle-xe 91 | ``` 92 | 93 | ## Other 94 | 95 | ### SQL 96 | 97 | _Note `sqlcl` is an alias for [SQLcl](https://www.oracle.com/database/technologies/appdev/sqlcl.html). Can also use `sqlplus`_ 98 | 99 | ```bash 100 | -- Connect to CDB 101 | sqlcl sys/Oracle18@localhost:32118/XE as sysdba 102 | 103 | 104 | -- Connect to default PDB 105 | sqlcl sys/Oracle18@localhost:32118/XEPDB1 as sysdba 106 | ``` 107 | 108 | ### APEX Install 109 | 110 | An example to install APEX into the default container is available [here](docs/apex-install.md). 111 | 112 | ### SSH into Container 113 | 114 | In some cases you may need to login to the server to modify or test something on the file system. 115 | 116 | ```bash 117 | docker exec -it oracle-xe bash -c "source /home/oracle/.bashrc; bash" 118 | 119 | # Once connected to run sqlplus: 120 | $ORACLE_HOME/bin/sqlplus sys/Oracle18@localhost/XE as sysdba 121 | $ORACLE_HOME/bin/sqlplus sys/Oracle18@localhost/XEPDB1 as sysdba 122 | 123 | 124 | # Listener start/stop 125 | $ORACLE_HOME/bin/lsnrctl stop 126 | $ORACLE_HOME/bin/lsnrctl start 127 | ``` 128 | 129 | ### OEM 130 | 131 | _Note: Flash is required_
132 | 133 | https://localhost:35518/em 134 | 135 | ### Creating a PDB 136 | 137 | First connect to the CDB as `sysdba`: `sqlcl sys/Oracle18@localhost:32118/XE as sysdba` 138 | 139 | ```sql 140 | -- Note XEPDB1 is created by default so demoing with XEPDB2 141 | create pluggable database xepdb2 admin user pdb_adm identified by Oradoc_db1 142 | file_name_convert=('/opt/oracle/oradata/XE/pdbseed','/opt/oracle/oradata/XE/XEPDB2'); 143 | 144 | -- Running the following query will show the newly created PDBs but they are not open for Read Write: 145 | select vp.name, vp.open_mode 146 | from v$pdbs vp; 147 | 148 | -- Open the PDB 149 | alter pluggable database xepdb2 open read write; 150 | 151 | -- If nothing is changed the PDBs won't be loaded on boot. 152 | -- They're a few ways to do this 153 | -- See for reference https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9531671900346425939 154 | -- alter pluggable database pdb_name save state; 155 | -- alter pluggable database all save state; 156 | -- alter pluggable database all except pdb$seed open read write 157 | alter pluggable database all save state; 158 | ``` 159 | 160 | To connect to the new PDB : 161 | 162 | ```bash 163 | # Note: the password is the CDB SYS password, not the pdb_adm admin user 164 | sqlcl sys/Oracle18@localhost:32118/XEPDB2 as sysdba 165 | ``` 166 | 167 | ### `emp` and `dept` tables 168 | 169 | Install `emp` and `dept` sample tables:
170 | 171 | `@https://raw.githubusercontent.com/OraOpenSource/OXAR/master/oracle/emp_dept.sql` 172 | 173 | 174 | ### Preserving `/opt/oracle/oradata` for Multiple Copies 175 | 176 | Each time you start a container that does has an empty `/opt/oracle/oradata` Oracle XE is configured and the data files are created for the CDB and one PDB (`XEPDB1`). If you plan to launch multiple separate containers for Oracle XE, it is unnecessary to spend this time waiting for the same base files to be created. The solution is fairly simple. It involves creating a sample/seed container, extracting the data files, then copying those data files each time you launch a new container for a new instance of Oracle XE. The following commands demonstrates how to do this: 177 | 178 | ```bash 179 | docker run -d \ 180 | --name=oracle-xe-seed \ 181 | oracle-xe:18c 182 | 183 | # Monitor the status: 184 | docker logs oracle-xe-seed 185 | 186 | # Once the Database is fully configured (you'll see a message like:) 187 | # "The following output is now a tail of the alert.log:" 188 | # Running docker ps oracle-xe-seed should also show status "(healthy)' 189 | # Copy the oradata files tso a location (ex: ~/docker/oracle-xe) 190 | # Note you'll probably want to store this in a shared NAS etc 191 | docker cp oracle-xe-seed:/opt/oracle/oradata ~/docker/oracle-xe-seed 192 | 193 | # You no longer need the container so stop and remove it 194 | docker stop oracle-xe-seed 195 | docker rm oracle-xe-seed 196 | ``` 197 | 198 | Each time you create a new instance of XE, copy the base `oradata` files and mount them as volume. The following examples shows how to create two copies of Oracle XE: 199 | 200 | ```bash 201 | # Copy the data files for 01 and 02 202 | cp ~/docker/oracle-xe-seed ~/docker/oracle-xe01 203 | cp ~/docker/oracle-xe-seed ~/docker/oracle-xe02 204 | 205 | # Start new containers 206 | docker run -d \ 207 | --name=oracle-xe01 \ 208 | -p 32181:1521 \ 209 | --network=oracle_network \ 210 | --volume ~/docker/oracle-xe01:/opt/oracle/oradata \ 211 | oracle-xe:18c 212 | 213 | docker run -d \ 214 | --name=oracle-xe02 \ 215 | -p 32182:1521 \ 216 | --network=oracle_network \ 217 | --volume ~/docker/oracle-xe02:/opt/oracle/oradata \ 218 | oracle-xe:18c 219 | 220 | # You should see both containers running now: 221 | docker ps 222 | 223 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 224 | 69b52a37a1c6 oracle-xe:18c "/bin/sh -c 'exec ${…" 8 minutes ago Up 8 minutes (health: starting) 5500/tcp, 0.0.0.0:32182->1521/tcp oracle-xe02 225 | 14eea4c699d3 oracle-xe:18c "/bin/sh -c 'exec ${…" 9 minutes ago Up 9 minutes (health: starting) 5500/tcp, 0.0.0.0:32181->1521/tcp oracle-xe01 226 | ``` 227 | 228 | ## Docker Developers 229 | 230 | If you're interested in helping maintain this project check out [docker-dev](docs/docker-dev.md) document. 231 | -------------------------------------------------------------------------------- /docs/apex-install.md: -------------------------------------------------------------------------------- 1 | # How to Install APEX in PDB 2 | 3 | 4 | 5 | - [How to Install APEX in PDB](#how-to-install-apex-in-pdb) 6 | - [Assumptions](#assumptions) 7 | - [APEX Installation](#apex-installation) 8 | - [ORDS](#ords) 9 | 10 | 11 | 12 | This documentation will walk through how to create a new PDB and install it. Please ensure that you have [downloaded](https://www.oracle.com/technetwork/developer-tools/apex/downloads/index.html) the latest copy of APEX. 13 | 14 | ## Assumptions 15 | 16 | Item | Description 17 | --- | --- 18 | Container Name | Container name is `oracle-xe` 19 | APEX Version | `18.2`. The zip file is located in: 20 | PDB | `XEPDB1` (_default PDB that comes with XE_) 21 | APEX Admin Password: `Oradoc_db1` 22 | 23 | 24 | ## APEX Installation 25 | 26 | ```bash 27 | # Copy APEX zip file to container 28 | docker cp ~/docker/files/apex/apex_18.2_en.zip oracle-xe:/tmp 29 | 30 | # Login to container 31 | docker exec -it oracle-xe bash -c "source /home/oracle/.bashrc; bash" 32 | 33 | # Next set of commands are in the container 34 | cd /tmp/ 35 | unzip apex_18.2_en.zip 36 | cd apex 37 | 38 | # Download APEX install file 39 | curl https://raw.githubusercontent.com/fuzziebrain/docker-oracle-xe/master/files/apex-install.sql --output apex-install.sql 40 | 41 | # Connect to PDB and install APEX 42 | $ORACLE_HOME/bin/sqlplus sys/Oracle18@localhost/XEPDB1 as sysdba @apex-install.sql Oradoc_db1 43 | 44 | # Delete APEX files 45 | cd /tmp 46 | rm -rf apex* 47 | 48 | exit 49 | ``` 50 | 51 | ## ORDS 52 | 53 | [docker-ords](https://github.com/martindsouza/docker-ords) contains instructions on how to setup a docker instance of ORDS 54 | -------------------------------------------------------------------------------- /docs/docker-dev.md: -------------------------------------------------------------------------------- 1 | # Docker Development for Oracle XE 2 | 3 | This document is for developers managing and contributing to this project. 4 | 5 | ## Scripts 6 | 7 | ### Run container and destroy: 8 | 9 | ```bash 10 | docker run -it --rm \ 11 | -p 32118:1521 \ 12 | --network=oracle_network \ 13 | --volume ~/docker/oracle-xe:/opt/oracle/oradata \ 14 | oracle-xe:18c 15 | ``` 16 | 17 | 18 | ## Documentation 19 | 20 | The TOC on the main [README.md](README.md) uses [Markdown TOC](https://marketplace.visualstudio.com/items?itemName=AlanWalk.markdown-toc) for VS Code. -------------------------------------------------------------------------------- /files/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fuzziebrain/docker-oracle-xe/b0c3459acb91ceeb8abc610aa131d466ea8c418c/files/.gitkeep -------------------------------------------------------------------------------- /files/apex-install.sql: -------------------------------------------------------------------------------- 1 | -- Example call: 2 | -- $ORACLE_HOME/bin/sqlplus sys/Oracle18@localhost/XEAPEX182 as sysdba @apex-install.sql Oradoc_db1 3 | -- 4 | -- Takes in 3 parameters: 5 | -- 1: admin_email ex: martin@talkapex.com 6 | -- 2: admin_pass ex: Oradoc_db1 7 | 8 | -- Must be run as SYS 9 | whenever sqlerror exit sql.sqlcode 10 | 11 | -- Parameters: If using to create another user later on, just modify this section 12 | define admin_email = 'changeme@changeme.com' 13 | define admin_pass = '&1' 14 | 15 | -- Validate parameters 16 | declare 17 | begin 18 | if '&admin_email.' is null then 19 | raise_application_error(-20001, 'Param 1: admin_email missing'); 20 | end if; 21 | 22 | if '&admin_pass.' is null then 23 | raise_application_error(-20001, 'Param 2: admin_pass missing'); 24 | end if; 25 | end; 26 | / 27 | 28 | -- Install APEX 29 | @apexins.sql SYSAUX SYSAUX TEMP /i/ 30 | 31 | -- APEX REST configuration 32 | -- In APEX 18.2 they're 3 parameters for this file 33 | @apex_rest_config_core.sql @ oracle oracle 34 | 35 | -- Required for ORDS install 36 | alter user apex_public_user identified by oracle account unlock; 37 | 38 | -- From Joels blog: http://joelkallman.blogspot.ca/2017/05/apex-and-ords-up-and-running-in2-steps.html 39 | declare 40 | l_acl_path varchar2(4000); 41 | l_apex_schema varchar2(100); 42 | begin 43 | for c1 in ( 44 | select schema 45 | from sys.dba_registry 46 | where comp_id = 'APEX') loop 47 | l_apex_schema := c1.schema; 48 | end loop; 49 | 50 | sys.dbms_network_acl_admin.append_host_ace( 51 | host => '*', 52 | ace => xs$ace_type(privilege_list => xs$name_list('connect'), 53 | principal_name => l_apex_schema, 54 | principal_type => xs_acl.ptype_db)); 55 | commit; 56 | end; 57 | / 58 | 59 | -- Setup APEX Admin password 60 | begin 61 | apex_util.set_security_group_id( 10 ); 62 | apex_util.create_user( 63 | p_user_name => 'ADMIN', 64 | p_email_address => '&admin_email.', 65 | p_web_password => '&admin_pass.', 66 | p_developer_privs => 'ADMIN', 67 | p_change_password_on_first_use => 'N'); 68 | apex_util.set_security_group_id( null ); 69 | commit; 70 | end; 71 | / 72 | -- Exit SQL 73 | exit -------------------------------------------------------------------------------- /scripts/checkDBStatus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copied from: https://github.com/oracle/docker-images/blob/master/OracleDatabase/SingleInstance/dockerfiles/18.3.0/checkDBStatus.sh 3 | 4 | # LICENSE UPL 1.0 5 | # 6 | # Copyright (c) 1982-2018 Oracle and/or its affiliates. All rights reserved. 7 | # 8 | # Since: May, 2017 9 | # Author: gerald.venzl@oracle.com 10 | # Description: Checks the status of Oracle Database. 11 | # Return codes: 0 = PDB is open and ready to use 12 | # 1 = PDB is not open 13 | # 2 = Sql Plus execution failed 14 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 15 | # 16 | 17 | ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`" 18 | POSITIVE_RETURN="READ WRITE" 19 | ORAENV_ASK=NO 20 | source oraenv 21 | 22 | # Check Oracle DB status and store it in status 23 | status=`su oracle -c '$ORACLE_HOME/bin/sqlplus -s / as sysdba' << EOF 24 | set heading off; 25 | set pagesize 0; 26 | SELECT open_mode FROM v\\$pdbs WHERE name COLLATE BINARY_CI = '$ORACLE_PDB'; 27 | exit; 28 | EOF` 29 | 30 | # Store return code from SQL*Plus 31 | ret=$? 32 | 33 | # SQL Plus execution was successful and PDB is open 34 | if [ $ret -eq 0 ] && [ "$status" = "$POSITIVE_RETURN" ]; then 35 | exit 0; 36 | # PDB is not open 37 | elif [ "$status" != "$POSITIVE_RETURN" ]; then 38 | exit 1; 39 | # SQL Plus execution failed 40 | else 41 | exit 2; 42 | fi; 43 | -------------------------------------------------------------------------------- /scripts/enableEmRemoteAccess.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . oraenv 4 | 5 | GLOBAL_ACCESS=${1:-N} 6 | 7 | if [ $GLOBAL_ACCESS = "Y" ]; then 8 | GLOBAL_ACCESS="true" 9 | else 10 | GLOBAL_ACCESS="false" 11 | fi; 12 | 13 | echo "Enabling XDB for external access" 14 | sqlplus / as sysdba << EOF 15 | exec dbms_xdb_config.setlistenerlocalaccess(false); 16 | exec dbms_xdb_config.setglobalportenabled($GLOBAL_ACCESS); 17 | EOF -------------------------------------------------------------------------------- /scripts/runOracle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Original source from: https://github.com/oracle/docker-images/blob/master/OracleDatabase/SingleInstance/dockerfiles/18.3.0/runOracle.sh 3 | 4 | # LICENSE UPL 1.0 5 | # 6 | # Copyright (c) 1982-2018 Oracle and/or its affiliates. All rights reserved. 7 | # 8 | # Since: November, 2016 9 | # Author: gerald.venzl@oracle.com 10 | # Description: Runs the Oracle Database inside the container 11 | # 12 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 13 | # 14 | 15 | ########### Move DB files ############ 16 | function moveFiles { 17 | 18 | if [ ! -d $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID ]; then 19 | mkdir -p $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/ 20 | fi; 21 | 22 | # Replace the container's hostname with 0.0.0.0 23 | sed -i 's/'$(hostname)'/0.0.0.0/g' $ORACLE_HOME/network/admin/listener.ora 24 | sed -i 's/'$(hostname)'/0.0.0.0/g' $ORACLE_HOME/network/admin/tnsnames.ora 25 | 26 | mv $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/ 27 | mv $ORACLE_HOME/dbs/orapw$ORACLE_SID $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/ 28 | mv $ORACLE_HOME/network/admin/sqlnet.ora $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/ 29 | mv $ORACLE_HOME/network/admin/listener.ora $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/ 30 | mv $ORACLE_HOME/network/admin/tnsnames.ora $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/ 31 | 32 | # oracle user does not have permissions in /etc, hence cp and not mv 33 | cp /etc/oratab $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/ 34 | 35 | symLinkFiles; 36 | } 37 | 38 | ########### Symbolic link DB files ############ 39 | function symLinkFiles { 40 | 41 | if [ ! -L $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora ]; then 42 | ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/spfile$ORACLE_SID.ora $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora 43 | fi; 44 | 45 | if [ ! -L $ORACLE_HOME/dbs/orapw$ORACLE_SID ]; then 46 | ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/orapw$ORACLE_SID $ORACLE_HOME/dbs/orapw$ORACLE_SID 47 | fi; 48 | 49 | if [ ! -L $ORACLE_HOME/network/admin/sqlnet.ora ]; then 50 | ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora 51 | fi; 52 | 53 | if [ ! -L $ORACLE_HOME/network/admin/listener.ora ]; then 54 | ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/listener.ora $ORACLE_HOME/network/admin/listener.ora 55 | fi; 56 | 57 | if [ ! -L $ORACLE_HOME/network/admin/tnsnames.ora ]; then 58 | ln -s $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora 59 | fi; 60 | 61 | # oracle user does not have permissions in /etc, hence cp and not ln 62 | cp $ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/oratab /etc/oratab 63 | 64 | } 65 | 66 | ########### SIGINT handler ############ 67 | function _int() { 68 | echo "Stopping container." 69 | echo "SIGINT received, shutting down database!" 70 | runuser oracle -s /bin/bash -c "${ORACLE_BASE}/scripts/${SHUTDOWN_FILE} immediate" 71 | } 72 | 73 | ########### SIGTERM handler ############ 74 | function _term() { 75 | echo "Stopping container." 76 | echo "SIGTERM received, shutting down database!" 77 | runuser oracle -s /bin/bash -c "${ORACLE_BASE}/scripts/${SHUTDOWN_FILE} immediate" 78 | } 79 | 80 | ########### SIGKILL handler ############ 81 | function _kill() { 82 | echo "SIGKILL received, shutting down database!" 83 | runuser oracle -s /bin/bash -c "${ORACLE_BASE}/scripts/${SHUTDOWN_FILE} abort" 84 | } 85 | 86 | ################################### 87 | # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # 88 | ############# MAIN ################ 89 | # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # 90 | ################################### 91 | 92 | # Check whether container has enough memory 93 | # Github issue #219: Prevent integer overflow, 94 | # only check if memory digits are less than 11 (single GB range and below) 95 | if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes | wc -c` -lt 11 ]; then 96 | if [ `cat /sys/fs/cgroup/memory/memory.limit_in_bytes` -lt 2147483648 ]; then 97 | echo "Error: The container doesn't have enough memory allocated." 98 | echo "A database container needs at least 2 GB of memory." 99 | echo "You currently only have $((`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`/1024/1024/1024)) GB allocated to the container." 100 | exit 1; 101 | fi; 102 | fi; 103 | 104 | # Set SIGINT handler 105 | trap _int SIGINT 106 | 107 | # Set SIGTERM handler 108 | trap _term SIGTERM 109 | 110 | # Set SIGKILL handler 111 | trap _kill SIGKILL 112 | 113 | # Commands 114 | ORACLE_CMD=/etc/init.d/oracle-xe-18c 115 | 116 | # Check whether database already exists 117 | if [ -d $ORACLE_BASE/oradata/$ORACLE_SID ]; then 118 | echo Database exists 119 | 120 | # Make sure audit file destination exists 121 | if [ ! -d $ORACLE_BASE/admin/$ORACLE_SID/adump ]; then 122 | mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/adump 123 | chown -R oracle.oinstall $ORACLE_BASE/admin 124 | fi; 125 | 126 | symLinkFiles; 127 | 128 | # Start database 129 | ${ORACLE_CMD} start 130 | 131 | else 132 | echo Database does not exists, configuring 133 | 134 | mkdir -p ${ORACLE_BASE}/oradata 135 | chown oracle.oinstall ${ORACLE_BASE}/oradata 136 | 137 | ${ORACLE_CMD} configure 138 | 139 | # Enable EM remote access 140 | runuser oracle -s /bin/bash -c "${ORACLE_BASE}/scripts/${EM_REMOTE_ACCESS} ${EM_GLOBAL_ACCESS_YN:-N}" 141 | 142 | # Move database operational files to oradata 143 | moveFiles; 144 | 145 | fi; 146 | 147 | # Check whether database is up and running 148 | # $ORACLE_BASE/scripts/$CHECK_DB_FILE 149 | # if [ $? -eq 0 ]; then 150 | # echo "#########################" 151 | # echo "DATABASE IS READY TO USE!" 152 | # echo "#########################" 153 | 154 | # else 155 | # echo "#####################################" 156 | # echo "########### E R R O R ###############" 157 | # echo "DATABASE SETUP WAS NOT SUCCESSFUL!" 158 | # echo "Please check output for further info!" 159 | # echo "########### E R R O R ###############" 160 | # echo "#####################################" 161 | # fi; 162 | 163 | # Tail on alert log and wait (otherwise container will exit) 164 | echo "The following output is now a tail of the alert.log:" 165 | tail -f ${ORACLE_BASE}/diag/rdbms/*/*/trace/alert*.log & 166 | childPID=$! 167 | wait ${childPID} 168 | 169 | # TODO workaround 170 | tail -f /dev/null 171 | -------------------------------------------------------------------------------- /scripts/shutdownDb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . oraenv 4 | 5 | $ORACLE_HOME/bin/sqlplus / as sysdba <