Create a docker environment for Oracle 11g XE

Overview

The procedure is as follows.

--Create a container image --Compatible with Windows / Linux version --Moderate setup with docker-compose etc.

Target

--People who want to launch an oracle instance including data on docker

Disclaimer

The code etc. described in this document is WTFPL2 license [^ 2] except for those derived from other reference materials [^ 1], and any guarantee There is no. [^ 1]: The ones derived from the reference materials are related to vagrant related code and docker build related [^ 2]: From Wikipedia: Do whatever you want, shit, public license (contract) The error handling is loose, so please improve it.

Preparation

In any folder (tools) [oracle-xe-11.2.0-1.0.x86_64.rpm.zip](http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index. html) (Oracle Database 11g Release 2 Express Edition for Linux x64) is downloaded. Place the following batch in any folder (tools).

get_oracle.bat(For windows)


set WORKING_DIR=%TMP%\oracle_build_wk
set CURRENT_DIR=%CD%
echo %WORKING_DIR%
mkdir %WORKING_DIR%
copy oracle-xe-11.2.0-1.0.x86_64.rpm.zip %WORKING_DIR%\
cd %WORKING_DIR%
curl --output Dockerfile.xe    -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/Dockerfile.xe
curl --output checkDBStatus.sh -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/checkDBStatus.sh
curl --output runOracle.sh     -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/runOracle.sh
curl --output setPassword.sh   -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/setPassword.sh
curl --output xe.rsp           -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/xe.rsp

docker build %WORKING_DIR% --force-rm=true --no-cache=true --shm-size=1G --build-arg DB_EDITION=xe -t oracle/database:11.2.0.2-xe -f Dockerfile.xe > %CURRENT_DIR%\oracle11g_build.log 2>&1
cd %CURRENT_DIR%
del /Q /S %WORKING_DIR%
echo DONE

get_oracle.sh(For Linux)


#!/bin/sh

WORKDIR=/tmp/oracle11
CURRENTDIR=$(pwd)
mkdir $WORKDIR
cp oracle-xe-11.2.0-1.0.x86_64.rpm.zip $WORKDIR/
cd $WORKDIR
curl --output Dockerfile.xe    -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/Dockerfile.xe
curl --output checkDBStatus.sh -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/checkDBStatus.sh
curl --output runOracle.sh     -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/runOracle.sh
curl --output setPassword.sh   -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/setPassword.sh
curl --output xe.rsp           -sSL --url https://github.com/oracle/docker-images/raw/master/OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/xe.rsp

DOCKEROPS=""
VERSION=11.2.0.2
EDITION="xe"
DOCKERFILE="Dockerfile"
DOCKEROPS="--shm-size=1G $DOCKEROPS";
IMAGE_NAME="oracle/database:$VERSION-$EDITION"
DOCKERFILE="$DOCKERFILE.$EDITION"
docker build ./ --force-rm=true --no-cache=true \
       $DOCKEROPS --build-arg DB_EDITION=$EDITION \
       -t $IMAGE_NAME -f $DOCKERFILE
cd $CURRENTDIR
rm -rf $WORKDIR
echo DONE

Run

Execute get_oracle.bat or get_oracle.sh.

docker-compose

If it is left as it is, it will not taste good at all, so I will post the recipe. (Since it is not persistent, the data will be reset if you recreate the container)

docker-compose.yml


version: '3'

services:
  ##Describe other services as needed
  oracledb_test:
    image: oracle/database:11.2.0.2-xe
    ports:
      - "1521:1521"
      #- "8080:8080"
    volumes:
      #The script here runs with dba privileges. If you want to use sqlplus, imp, etc., place the sh file
      #Since it is read-only, be careful when outputting a log file.
      - ./oracledb/setup:/u01/app/oracle/scripts/setup:ro
      #Conte later
      - ./oracledb/mnt:/mnt/local
    shm_size: 1g
    environment:
      - NLS_LANG=Japanese_Japan.UTF8
      - TZ=Asia/Tokyo

oracledb\setup\00_user_create.sql(UTF-8)



--You will be given a password without permission, so change it.(Please specify an absolutely different password)
ALTER USER sys IDENTIFIED BY manager;
ALTER USER system IDENTIFIED BY manager;

--User created
CREATE USER test_user IDENTIFIED BY test_user DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp QUOTA UNLIMITED ON users;
--Role creation
create role conn_testuser;
GRANT CREATE session, CREATE sequence, CREATE trigger, CREATE table, CREATE view, CREATE procedure, CREATE synonym TO conn_scn;
--Authorization
GRANT conn_testuser TO test_user;
--It closes without permission, so you don't need to exit.

When inputting data with sql, create the following file.

oracledb\setup\01_ddl.sql(UTF-8)



--Switch schema
ALTER SESSION SET CURRENT_SCHEMA = test_user;

--Table creation, etc.

--It closes without permission, so you don't need to exit.

Bonus: vagrant

If you want to set up an Oracle instance on Vagrant, you can create an image by writing as follows. Make sure the virtual machine instance memory is at least 2G. (Otherwise you will not be able to start oracle)

Vagrantfile


# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  #Omission
  #if Vagrant.has_plugin?("vagrant-cachier")
  #  config.cache.scope = :box 
  #end

  #Omission
  config.vm.provision "docker", run: "always"
  #from here
  # Setup docker image for oracle 11g XE environment
    config.vm.synced_folder "./tools", "/tmp/tools", create: true
    config.vm.provision "shell", inline: <<-SHELL
      cd /tmp/tools
      /bin/sh ./get_oracle.sh
    SHELL
  #So far

  config.vm.provision "docker_compose",
                      compose_version: "1.24.1",
                      yml: "/vagrant/docker/docker-compose.yml",
                      run: "always"

end

References

Recommended Posts

Create a docker environment for Oracle 11g XE
Create a Vue3 environment with Docker!
Create a web environment quickly using Docker
Build a development environment for Docker + Rails6 + Postgresql
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
[Memo] Create a CentOS 8 environment easily with Docker
Create a Privoxy + Tor environment instantly using Docker
[Docker] How to create a virtual environment for Rails and Nuxt.js apps
Build a development environment for Docker, java, vscode
Create a java web application development environment with docker for mac part2
Create a Spring Boot development environment with docker
[Note] Create a java environment from scratch with docker
[2021] Build a Docker + Vagrant environment for using React / TypeScript
[Docker] Create Elasticsearch, Kibana environment!
Create a Docker image with the Oracle JDK installed (yum
I tried to create a padrino development environment with Docker
[Oracle Cloud] Create a development environment for OCI Java SDK (Visual Studio Code, Maven, CentOS)
Build a Node.js environment with Docker
Create a lightweight STNS Docker image
Environment construction with Docker for beginners
Create a database in a production environment
Create SolrCloud verification environment with Docker
Create Laravel environment with Docker (docker-compose)
Jupyter's Docker environment for running TensorFlow
Create a fluentd server for testing
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
(For myself) Try creating a C # environment with docker + code-server, cloud9
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS
Create a Docker Image for redoc-cli and register it on Docker Hub
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Build a PureScript development environment with Docker
Create Rails 6 + MySQL environment with Docker compose
Command line that can create a directory structure for building a Laravel environment with Docker in one shot
How to create a Maven repository for 2020
Creating a java web application development environment with docker for mac part1
Create Spring Boot-gradle-mysql development environment with Docker
Let's create a Java development environment (updating)
[Docker] Create Node.js + express + webpack environment with Docker
A note about trying Oracle 11g + Spring boot with Vagrant + Docker compose
Build a local development environment for Rails tutorials with Docker (Rails 6 + PostgreSQL + Webpack)
Build a Wordpress development environment with Docker
Docker Compact Manual (4: Create a custom image)
Install Docker and create Java runtime environment
Build a simple Docker + Django development environment
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
Create a Docker container for your development web server in Ansible on MacOS
Build a development environment to create Ruby on Jets + React apps with Docker
[Introduction to Docker] Create a Docker image for machine learning and use Jupyter notebook
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Build a Laravel / Docker environment with VSCode devcontainer
Building a Ruby environment for classes on Mac
Build a WordPress development environment quickly with Docker
How to create pagination for a "kaminari" array
INTERNAL ERROR: cannot create temporary directory !: Docker environment
[Java] Let's create a mod for Minecraft 1.14.4 [Introduction]
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
Build a simple Docker Compose + Django development environment
Create a tool for name identification in Salesforce
Build a container for Docker x Laravel phpMyAdmin
Prepare a scraping environment with Docker and Java
A reminder of Docker and development environment construction