docker 로 oracle 이미지 다운받고 사용하기
리눅스에 도커 설치해두었고 오라클db를 사용해볼까 합니다.
처음에 그냥 이미지 바로 받아서 사용할려고 하니 계정 접속이 안되서 좀 해매면서 다시 다운받았습니다.
버전은 oracle-12c
1) docker login
$ docker login -u <username> -p <password>
or
$ docker login [enter]
username : [dockerid] [enter]
password : [dockerPassword] [enter] 본인 아이디, 패스워드 입력해주세요
docker 계정 있으시겠죠?
2) docker pull
docker pull wvbirder/database-enterprise:12.2.0.1-slim
pull 되면 docker images 명령어로 잘들어와 있는지 확인
3) 오라클 컨테이너 실행
docker run -dit --name local_db -p 1521:1521 wvbirder/database-enterprise:12.2.0.1-slim
실행 후에
docker ps 로 정상적으로 프로세스가 떳는지 한번더 확인 해주세요
4) docker 실행 로그를 확인하면서 완료될때 까지 대기합니다.
docker logs -f local_db
root@gusdn12p-187840:~# docker logs -f local_db
Setup Oracle Database
Oracle Database 12.2.0.1 Setup
Wed Feb 8 07:19:48 UTC 2023
Check parameters ......
log file is : /home/oracle/setup/log/paramChk.log
paramChk.sh is done at 0 sec
untar DB bits ......
log file is : /home/oracle/setup/log/untarDB.log
untarDB.sh is done at 35 sec
config DB ......
log file is : /home/oracle/setup/log/configDB.log
Wed Feb 8 07:20:23 UTC 2023
Start Docker DB configuration
Call configDBora.sh to configure database
Wed Feb 8 07:20:24 UTC 2023
Configure DB as oracle user
Setup Database directories ...
SQL*Plus: Release 12.2.0.1.0 Production on Wed Feb 8 07:20:25 2023
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to an idle instance.
SQL>
File created.
SQL> ORACLE instance started.
Total System Global Area 1342177280 bytes
Fixed Size 8792536 bytes
Variable Size 352323112 bytes
Database Buffers 973078528 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.
SQL>
Database altered.
SQL>
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /u01/app/oracle/product/12.2.0
/dbhome_1/dbs/spfileORCLCDB.or
a
SQL>
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
encrypt_new_tablespaces string CLOUD_ONLY
SQL>
User altered.
SQL>
User altered.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
update password
Enter password for SYS:
create pdb : ORCLPDB1
SQL*Plus: Release 12.2.0.1.0 Production on Wed Feb 8 07:20:49 2023
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> 2 3 4 5
Pluggable database created.
SQL>
Pluggable database altered.
SQL>
Pluggable database altered.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Reset Database parameters
SQL*Plus: Release 12.2.0.1.0 Production on Wed Feb 8 07:21:09 2023
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL>
System altered.
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 08-FEB-2023 07:21:09
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Starting /u01/app/oracle/product/12.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/12.2.0/dbhome_1/admin/ORCLCDB/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/59d582017b98/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=0.0.0.0)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 08-FEB-2023 07:21:10
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.2.0/dbhome_1/admin/ORCLCDB/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/59d582017b98/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
DONE!
Remove password info
Docker DB configuration is complete !
configDB.sh is done at 82 sec
Done ! The database is ready for use .
# ===========================================================================
# == Add below entries to your tnsnames.ora to access this database server ==
# ====================== from external host =================================
ORCLCDB=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<ip-address>)(PORT=<port>))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCLCDB.localdomain)))
ORCLPDB1=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<ip-address>)(PORT=<port>))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCLPDB1.localdomain)))
#
#ip-address : IP address of the host where the container is running.
#port : Host Port that is mapped to the port 1521 of the container.
#
# The mapped port can be obtained from running "docker port <container-id>"
# ===========================================================================
2023-02-08T07:21:06.068678+00:00
ORCLPDB1(3):Opatch validation is skipped for PDB ORCLPDB1 (con_id=0)
2023-02-08T07:21:09.510869+00:00
ORCLPDB1(3):Opening pdb with no Resource Manager plan active
Pluggable database ORCLPDB1 opened read write
Completed: alter pluggable database ORCLPDB1 open
alter pluggable database all save state
Completed: alter pluggable database all save state
2023-02-08T07:21:09.825630+00:00
ALTER SYSTEM SET encrypt_new_tablespaces='DDL' SCOPE=BOTH; ==> 이 부분이 나오면 완료 된것이라고 합니다.
5) 유저생성
docker exec -it local_db bash -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1@ORCLCDB as sysdba"
유저 생성후 권한도 줍니다.
SQL> alter session set "_ORACLE_SCRIPT"=true;
SQL> grant connect, resource, dba to test;
SQL> commit;
한국 시간대와 한글 설정을 위해 문자 코드셋 설정
update sys.props$ set value$='KO16MSWIN949' where name='NLS_CHARACTERSET';
update sys.props$ set value$='KO16MSWIN949' where name='NLS_NCHAR_CHARACTERSET';
update sys.props$ set value$='AMERICAN_AMERICA.KO16MSWIN949' where name='NLS_LANGUAGE';
작업후 commit;
커밋후 shutdown immediate; (데이터 베이스를 재기동함)
전에 몇번 mysql사용하는데 sysdate 같은 기능을 사용하니 미국 시간이 찍히고 해서 상당히 바꾸는데 오래걸렸습니다..
자료는 많은데 이상하게 안바뀌더라구요
이제 오라클 연결이 잘되는지 확인해봐야 합니다.
저는 보통 Mysql이나 MariaDB를 사용할때는 HeidSQL을 사용하는데
오라클은 디비버로 사용하겠습니다.
빨간 표시된 저 버튼을 누르시면 아래 창이나옵니다.
보통 본인 컴퓨터면 Host 는 localHost로 놔두시고 다른서버를 사용중이시면 서버 ip를 적어주시면 됩니다.
Database는 밑에 명령어를 사용하시면 알수있습니다. 그리고 Database: 적는칸 옆에 SID라고 있는걸로 꼭 설정해주셔야 합니다.
select name from v$database;
다적어주시고 username에는 아까 만든 본인 아이디와 패스워드 입력하고 왼쪽하단에 test Connection있는데 눌러주시면 되겠습니다. 끝~