├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── Vagrantfile ├── step1 ├── Dockerfile ├── db_install.rsp ├── dbca.rsp ├── install.sh ├── install_rlwrap.sh ├── limits.conf ├── oraInst.loc └── sysctl.conf └── step2 ├── Dockerfile ├── colorecho ├── create_database.sh ├── db_template.dbt ├── entrypoint_oracle.sh └── ora_env /.gitignore: -------------------------------------------------------------------------------- 1 | database/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 bofm 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 | 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | REPO = bofm/oracle12c 2 | NAME = aa_oracle_zz 3 | CURDIR = `pwd` 4 | SHM_SIZE = 1GB 5 | OPTS = --shm-size $(SHM_SIZE) 6 | DOCKER_SAVE_FILENAME = docker_img_oracle_database_created_$$(date +%Y-%m-%d).tgz 7 | ccred=\033[0;31m 8 | ccgreen=\033[32m 9 | ccyellow=\033[0;33m 10 | ccend=\033[0m 11 | 12 | .PHONY: all 13 | 14 | # Use bofm/oracle12c:preinstall from Docker Hub 15 | all: install postinstall 16 | 17 | # Build from scratch 18 | full: preinstall install postinstall 19 | docker-save: docker-commit-created docker-save-created 20 | 21 | docker_cleanup: 22 | @[ `docker images -q --filter "dangling=true"| wc -l` -gt 0 ] && docker rmi `docker images -q --filter "dangling=true"` || true 23 | @[ `docker volume ls -q --filter "dangling=true"| wc -l` -gt 0 ] && docker volume rm `docker volume ls -q --filter "dangling=true"` || true 24 | 25 | clean: 26 | @echo `docker rm -v $(NAME) > /dev/null 2>&1 && echo Container "oracle" has been removed.` 27 | 28 | preinstall: 29 | @echo "$(ccgreen)Building base image...$(ccend)" 30 | # The following loop is a workaround for the bug of "docker build", related to device mapper. 31 | # Bug example: 32 | # INFO[0019] Error getting container ea069f9ff24469184e70e5ce9b2d6132a31109bf1d0a3e0e5d30e50da8cbd0b6 from driver devicemapper: 33 | # Error mounting '/dev/mapper/docker-8:1-263449-ea069f9ff24469184e70e5ce9b2d6132a31109bf1d0a3e0e5d30e50da8cbd0b6' on 34 | # '/var/lib/docker/devicemapper/mnt/ea069f9ff24469184e70e5ce9b2d6132a31109bf1d0a3e0e5d30e50da8cbd0b6': no such file or directory 35 | @for n in `seq 10`; do \ 36 | docker build -t $(REPO):preinstall step1 &&\ 37 | break || echo "$(ccred)******* FAILED $$n times$(ccend)" && sleep 2;\ 38 | done 39 | 40 | postinstall: 41 | @echo "$(ccgreen)Building the final image...$(ccend)" 42 | @for n in `seq 10`; do \ 43 | docker build -t $(REPO):latest step2 &&\ 44 | break || echo "$(ccred)******* FAILED $$n times$(ccend)" && sleep 2;\ 45 | done 46 | @echo "$(ccgreen)Image created: $(REPO):latest$(ccend)" 47 | @docker images $(REPO) 48 | 49 | install: 50 | @echo "$(ccgreen)Installing Oracle Database software...$(ccend)" 51 | @if docker ps -a|grep $(NAME)_install; then docker rm $(NAME)_install; fi 52 | @docker run $(OPTS) --name $(NAME)_install -v $(CURDIR)/../database:/tmp/install/database $(REPO):preinstall /tmp/install/install.sh 53 | @echo "$(ccgreen)Committing image with tag 'installed'...$(ccend)" 54 | @docker commit $(NAME)_install $(REPO):installed 55 | @docker rm $(NAME)_install 56 | 57 | bash: 58 | @docker run -it --rm $(OPTS) --name $(NAME) $(REPO) bash 59 | 60 | bash-v: 61 | docker run -it --rm -v /data $(OPTS) --name $(NAME) $(REPO) bash 62 | 63 | test: 64 | docker run -it -v /data $(OPTS) --name $(NAME) $(REPO) database 65 | docker start -ia $(NAME) 66 | docker rm -v $(NAME) 67 | 68 | test2: 69 | docker run -it -v /data $(OPTS) --name $(NAME) $(REPO) database 70 | docker rm -v $(NAME) 71 | 72 | test3: 73 | docker run -it $(OPTS) --name $(NAME) $(REPO) database 74 | docker rm -v $(NAME) 75 | 76 | docker-commit-created: 77 | @echo "$(ccgreen)Running new container and creating database...$(ccend)" 78 | docker run -d $(OPTS) --name $(NAME) $(REPO) database 79 | docker logs -f $(NAME) & 80 | @while true; do \ 81 | docker logs $(NAME) 2>/dev/null | grep "Database created." && break || sleep 20; \ 82 | done 83 | @echo "$(ccgreen)Stopping container...$(ccend)" 84 | docker stop -t 120 $(NAME) 85 | @echo "$(ccgreen)Committing image with tag '$(REPO):created' ...$(ccend)" 86 | docker commit $(NAME) $(REPO):created 87 | 88 | docker-save-created: 89 | @echo "$(ccgreen)Saving image...$(ccend)" 90 | docker save $(REPO):created | gzip -c > $(DOCKER_SAVE_FILENAME) 91 | @docker rm $(NAME) > /dev/null 92 | @echo "$(ccgreen)Image saved to: `readlink -f $(DOCKER_SAVE_FILENAME)`$(ccend)" 93 | 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Goals 2 | * Provide an easy way to build a lightweight [Docker](http://www.docker.com/) image for [Oracle Database](http://docs.oracle.com/database/121/index.htm). 3 | * Just run a database and skip the complexities of installation and configuration. 4 | 5 | ## Features 6 | * `docker run` creates and starts up a new database or the existing database, if it is already created. 7 | * `docker logs` shows all the logs prefixed with log source (in the style of syslog). 8 | * Uses `trap` to handle signals and shutdown gracefully. 9 | * Data and logs are stored in `/data` so that `-v /data` could be used. 10 | * Total memory used by Oracle instance (MEMORY_TARGET) is set depending on `--shm-size` parameter. 11 | * rlwrap can be installed by running `bash /tmp/install/install_rlwrap.sh` (+ 50 MB on disk). 12 | 13 | 14 | ## Build 15 | Optional: if you are using [Vagrant](https://www.vagrantup.com/), you can use this [Vagrantfile](Vagrantfile) for your build environment. 16 | 17 | 1. download `linuxamd64_12102_database_1of2.zip` and `linuxamd64_12102_database_2of2.zip` from [oracle.com](http://www.oracle.com/technetwork/database/enterprise-edition/downloads/database12c-linux-download-2240591.html) **and extract the archives to current directory**. 18 | 2. Execute the following lines in bash and wait ~15 minutes: 19 | ```shell 20 | git clone https://github.com/bofm/docker-oracle12c.git 21 | cd docker-oracle12c 22 | make all 23 | ``` 24 | 25 | ## Usage 26 | *Note: In the following examples `oracle_database` is the name of the container.* 27 | 28 | * Create or run database and listener 29 | * Daemon mode 30 | 31 | ```bash 32 | # Create and start 33 | docker run -d --shm-size 1GB --name oracle_database -p 1521:1521 -v /data bofm/oracle12c 34 | # Stop 35 | docker stop -t 120 oracle_database 36 | # Start again 37 | docker start oracle_database 38 | ``` 39 | **Important:** Always stop with `-t`, otherwise Docker will kill the database instance, if it doesn't shut down in 10 seconds. 40 | * Foreground mode 41 | 42 | ```bash 43 | # Start 44 | docker run -it --shm-size 1GB --name oracle_database -p 1521:1521 -v /data bofm/oracle12c 45 | # `ctrl+c` (SIGINT) to stop 46 | ``` 47 | 48 | * Create a gzipped tar archive suitable for `docker load` (an archive of the image with a created database and without volumes) 49 | 50 | It is recommended to use large (>=20GB, the default is 10GB) Docker base volume size, for which Vagrant with [Vagrantfile](Vagrantfile) can be used. 51 | 52 | ```bash 53 | # Build everything and save the created image to a file. 54 | # This will echo something like this: 55 | # Image saved to: /some/path/docker_img_oracle_database_created_YYYY-MM-DD.tgz 56 | make all docker-save 57 | 58 | # The saved image can be loaded from the file 59 | # The image will be loaded with tag bofm/oracle12c:created 60 | docker load < docker_img_oracle_database_created_YYYY-MM-DD.tgz 61 | 62 | # Run the image in the new container 63 | # Daemon 64 | docker run -d --shm-size 1GB --name oracle_database -p 1521:1521 bofm/oracle12c:created 65 | # Foreground 66 | docker run -it --shm-size 1GB --name oracle_database -p 1521:1521 bofm/oracle12c:created 67 | ``` 68 | 69 | * Logs 70 | 71 | ```bash 72 | # Check all the logs in one place 73 | docker logs oracle_database 74 | 75 | # Check alert log 76 | docker logs oracle_database | grep alertlog: 77 | 78 | # Check listener log 79 | docker logs oracle_database | grep listener: 80 | ``` 81 | 82 | * SQL*Plus, RMAN or any other program 83 | 84 | ```bash 85 | # Bash 86 | # as root 87 | docker exec -it -u root oracle_database bash 88 | # as oracle 89 | docker exec -it oracle_database bash 90 | 91 | # Run sqlplus in the running container 92 | docker exec -it oracle_database sqlplus / as sysdba 93 | 94 | # Run rman in the running container 95 | docker exec -it oracle_database rman target / 96 | 97 | # Run sqlplus in a separate container and 98 | # connect to the database in the linked container 99 | docker run -it --rm --link oracle_database:oradb bofm/oracle12c sqlplus sys/sys@oradb/ORCL as sysdba 100 | ``` 101 | 102 | * Start listener only (not sure if anybody needs it :) ) 103 | 104 | ```bash 105 | docker run -d --name listener -p 1521:1521 bofm/oracle12c listener 106 | # Or link it to the running container 107 | docker run -d --name listener -p 1521:1521 --link bofm/oracle12c listener 108 | ``` 109 | 110 | ### Compatibility 111 | * Tested on Docker 1.12 112 | 113 | ### Limitations and Bugs 114 | * `--shm-size` option is required to mount /dev/shm to use Oracle's automatic memory management. 115 | * Oracle Database doesn't work with Docker ZFS storage driver by default. Check [this issue](https://github.com/bofm/docker-oracle12c/issues/10) for the workaround. 116 | * Database options and sample schemas installation through DBCA is a mystery. In this repo dbca is run with `-sampleSchema true` and [db_template.dbt](step2/db_template.dbt) contains this line `