Docker oracle 설치 - Docker oracle seolchi

도커(Docker)를 이용해서 오라클 RDBMS를 설치해보자.

오라클 도커 이미지 받기

우선 도커에 공개되어 있는 오라클 11g 이미지들을 검색해보자. "docker search oracle-xe-11g"를 실행해보면 오라클 도커 이미지들을 확인할 수 있다.

$ docker search oracle-xe-11g NAME DESCRIPTION STARS OFFICIAL AUTOMATED oracleinanutshell/oracle-xe-11g 206 wnameless/oracle-xe-11g-r2 Oracle Express Edition 11g Release 2 on Ubun… 79 orangehrm/oracle-xe-11g docker container with Oracle Express Editio… 16 [OK] jaspeen/oracle-xe-11g Fork from sath89/docker-oracle-xe-11g - smal… 6 [OK] christophesurmont/oracle-xe-11g Clone of the wnameless/oracle-xe-11g. 6 ukhomeofficedigital/oracle-xe-11g Oracle Database Express Edition 11g Container 4 [OK] thebookpeople/oracle-xe-11g 3 wscherphof/oracle-xe-11g-r2 Oracle® Database Express Edition 11g Release… 3 acktsw/oracle-xe-11g fork from //hub.docker.com/r/sath89/or… 2 [OK] mcgregorandrew/oracle-xe-11g Oracle image with password expiry time set t… 2 alxfduch/oracle-xe-11g-tridion Oracle Express 11g R2 on Ubuntu 16.04 LTS Tr… 2 webdizz/oracle-xe-11g-sa This is a simple image based on sath89/oracl… 1 [OK] dotcms/oracle-xe-11g 0 zeroturnaround/oracle-xe-11g 0 activeeon/oracle-xe-11g 0 nritholtz/oracle-xe-11g nritholtz/oracle-xe-11g 0 andyrbell/oracle-xe-11g-centos Oracle Express Edition 11g Release 2 on Cent… 0 gaesi/oracle-xe-11g Based on: oracleinanutshell/oracle-xe-11g 0 switchsoftware/oracle-xe-11g 0 aerisconsulting/oracle-xe-11g Oracle Express 11g R2 on Ubuntu 16.04 LTS (b… 0 paliari/oracle-xe-11g 0 jark/oracle-xe-11g-r2-cdc 0 avuletica/oracle-xe-11g-r2 Dockerfile of Oracle Database Express Editio… 0 larmic/oracle-xe-11g Using wnameless/oracle-xe-11g with created u… 0 toneloc01/oracle-xe-11g Out-of-the-box oralce xe image from ubuntu 1… 0

저 중에 하나를 docker pull 명령을 이용해서 받으면 된다.

$ docker pull jaspeen/oracle-xe-11g Using default tag: latest latest: Pulling from jaspeen/oracle-xe-11g Image docker.io/jaspeen/oracle-xe-11g:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at //docs.docker.com/registry/spec/deprecated-schema-v1/ 863735b9fd15: Downloading [=====================> ] 27.89MB/65.67MB 4fbaa2f403df: Download complete 44be94a95984: Download complete a3ed95caeb02: Download complete 05b9ddeb40d9: Download complete b44894d2d2af: Download complete 1492d1fc5b9f: Download complete c0f3c6ec8986: Waiting fbfc89a21b1b: Waiting 740047056d21: Waiti

오라클 도커 컨테이너 실행

이제 받은 오라클 도커 이미지를 이용해서 오라클 인스턴스를 띄워보자.

$ docker run --name oracle -d -p 1521:1521 jaspeen/oracle-xe-11g

이제 sqlplus 를 실행해서 오라클 인스턴스에 붙어보자

$ docker exec -it oracle sqlplus SQL*Plus: Release 11.2.0.2.0 Production on Fri Feb 25 12:44:34 2022 Copyright (c) 1982, 2011, Oracle. All rights reserved. Enter user-name: system Enter password: Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL>

user-name은 "system"을 입력하면 되고 password는 oracle이다.

이제 sqlplus 화면이 떴다. 이제 오라클 DB를 이용하면 된다.

Oracle Database를 docker로 설치하는 방법이 타 DB보다 조금 복잡하여 글로 남겨보려고 합니다.

mariadb나 postgresql의 경우 그냥 hub.docker.com에서 container image를 바로 pull하면 됩니다.

$ sudo apt install docker docker-compose git -y

시작하기 전, docker, docker-compose, git이 설치되어 있지 않다면 설치 후 진행해야 합니다.

$ git clone //github.com/oracle/docker-images

Oracle사에선 Oracle Database를 docker로 빌드하기 위한 스크립트를 제공합니다. git clone 명령어를 사용하여 다운로드합니다.

$ cd docker-images/OracleDatabase/SingleInstance/dockerfiles $ ./buildContainerImage.sh -v 18.4.0 -x

그리고 buildContainerImage.sh 를 실행하여 docker 이미지를 빌드합니다.

-v 옵션은 버전,

-x 옵션은 빌드 대상의 데이터베이스가 Express Edition임을 의미합니다.

버전은 18c Express 를 선택했습니다. 18 이외의 버전을 사용할 시 binary를 따로 다운로드 받은 후 dockerfiles 아래의 폴더 (dockerfiles/<version>)에 넣으셔야 합니다. 자세한 것은 //github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md#building-oracle-database-container-images 를 참고해주세요.

buildContainerImage.sh 스크립트 파일을 실행하시면 알아서 빌드가 진행됩니다.

빌드가 좀 오래 걸립니다. i5-4590/8GB 시스템에서 2563초가 걸렸습니다. (42분) 18c Express binary 다운로드 때문에 이렇게 걸린 것 같습니다.

2. docker 컨테이너 생성

$ cd ~/oracle $ vi docker-compose.yml

docker 실행을 위해 docker-compose.yml을 생성합니다.

version: "3" services: oracle-xe-18c: image: oracle/database:18.4.0-xe container_name: oracle-xe-18c restart: unless-stopped ports: - 1521:1521 - 5500:5500 volumes: # The data volume to use for the database. # Has to be writable by the Unix "oracle" (uid: 54321) user inside the container! # If omitted the database will not be persisted over container recreation. - ./oradata:/opt/oracle/oradata # Optional: A volume with custom scripts to be run after database startup. # For further details see the "Running scripts after setup and on startup" section below. #- ./scripts/startup:/opt/oracle/scripts/startup # Optional: A volume with custom scripts to be run after database setup. # For further details see the "Running scripts after setup and on startup" section below. #- ./scripts/setup:/opt/oracle/scripts/setup environment: # The Oracle Database SYS, SYSTEM and PDB_ADMIN password (default: auto generated). - ORACLE_PWD=1234 # The character set to use when creating the database (default: AL32UTF8). #- ORACLE_CHARACTERSET=AL32UTF8

docker-compose.yml 의 내용은 위와 같이 작성합니다. 영어로 된 주석은 GitHub에서 가져온 것입니다. 상황에 맞게 주석 해제하여 사용하시면 됩니다. 자세한 내용은 //github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md#running-oracle-database-18c-express-edition-in-a-container 를 참고해주세요.

비밀번호는 ORACLE_PWD 환경변수를 수정하여 변경할 수 있습니다.

데이터는 oradata 폴더에 저장되도록 지정하였습니다.

Oracle Database는 컨테이너 내부적으로 54321이라는 UID를 사용하기 때문에, 폴더에 권한을 설정하여야 데이터가 정상적으로 저장됩니다.

$ mkdir oradata $ sudo chown 54321 oradata

위의 명령어를 입력하여 oradata 폴더를 생성하고 소유자를 54321로 바꿔주세요.

3. docker 실행

$ docker-compose up -d

위의 명령을 실행하면 docker-compose.yml 에서 정의했던 내용대로 docker 컨테이너가 생성 · 실행됩니다.

$ docker-compose ps -a

정상적으로 컨테이너가 실행에 성공했는지 확인하기 위해 위의 명령어를 입력합니다.

State에서, (health: starting) 이라고 뜨면 컨테이너가 켜지는 중이라는 뜻입니다. (healthy)가 될 때까지 기다려야 합니다. 저는 약 6~8분정도 걸렸습니다. 아마 초기 세팅때문에 조금 오래 걸린 것 같네요.

$ docker-compose down

docker-compose down 을 입력하면 컨테이너가 종료됩니다.

4. Oracle Database 연결

sqldeveloper를 사용하여 방금 생성한 Oracle Database 컨테이너에 연결합니다.

위와 같이 입력해주시면 됩니다. 비밀번호는 아까 docker-compose.yml 에서 설정한 대로 입력하면 됩니다.

docker를 로컬에서 실행중이면 호스트 이름에는 localhost를 입력하시면 됩니다. 외부 서버에서 실행중이라면 해당 서버 주소를 입력하시면 됩니다.

접속이 잘 된 것을 확인할 수 있습니다.

Toplist

최신 우편물

태그