星期一, 5月 25, 2020

如何快速地下載並啟動一個Oracle 12.2 docker image

前言:
在以往安裝Oracle必須要從Oracle官方網站下載,而現在
有了docker社群裡面由原廠或是社群提供的image,就可以透過pull的方式直接下載,這樣測試與開發真的快上非常非常多。

趁著休假時間來玩一下怎麼從docket community pull oracle 12c image

首先請先在docker社群註冊你的帳號

測試步驟:

yum install -y docker

chkconfig docker on

# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:        .                                  [  OK  ]

As ec2-user user :

$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: jaychu649
Password:
WARNING! Your password will be stored unencrypted in /home/ec2-user/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

#ref 2
$sudo chmod 666 /var/run/docker.sock
$sudo docker pull store/oracle/database-enterprise:12.2.0.1
12.2.0.1: Pulling from store/oracle/database-enterprise
4ce27fe12c04: Pull complete
9d3556e8e792: Pull complete
fc60a1a28025: Pull complete
0c32e4ed872e: Pull complete
b465d9b6e399: Pull complete
Digest: sha256:40760ac70dba2c4c70d0c542e42e082e8b04d9040d91688d63f728af764a2f5d
Status: Downloaded newer image for store/oracle/database-enterprise:12.2.0.1
docker.io/store/oracle/database-enterprise:12.2.0.1

$ docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
store/oracle/database-enterprise   12.2.0.1            12a359cd0528        2 years ago         3.44GB

以名稱 JayDevDB 來建立容器
$ docker run -d -it --name JayDevDB -p 1521:1521 store/oracle/database-enterprise:12.2.0.1
786f903dca1a50deeff130fa2a9bf4b422a7ec4db3ad370d6b01ffe5a62ba865

$ docker start JayDevDB

$ sudo docker exec -it JayDevDB bash -c "source /home/oracle/.bashrc; sqlplus /nolog"

SQL> connect sys as sysdba;
Enter password: welcome1
Connected.
SQL>

alter session set "_ORACLE_SCRIPT"=true;
create user testuser identified by testuser;
GRANT CONNECT, RESOURCE, DBA TO testuser;

SQL>select value from v$parameter where name='service_names';
VALUE
--------------------------------------------------------------------------------
ORCLCDB.localdomain

SQL> exit

$ sudo docker exec -it JayDevDB bash -c "source /home/oracle/.bashrc; sqlplus testuser/testuser"

SQL> select instance_name, status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
ORCLCDB          OPEN

SQL> archive log list;
ORA-01031: insufficient privileges

取得docket internal ip address:

$ sudo docker inspect 786f903dca1a50deeff130fa2a9bf4b422a7ec4db3ad370d6b01ffe5a62ba865 |grep -i ip
"IPAddress": "172.17.0.2",

or use:

$ sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' 786f903dca1a50deeff130fa2a9bf4b422a7ec4db3ad370d6b01ffe5a62ba865
172.17.0.2

$ netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         172.31.0.1      0.0.0.0         UG        0 0          0 eth0
169.254.169.254 0.0.0.0         255.255.255.255 UH        0 0          0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U         0 0          0 docker0
172.31.0.0      0.0.0.0         255.255.240.0   U         0 0          0 eth0

$ telnet 172.17.0.2 1521
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.

#Connecting to another RDS Oracle instance using the Oracle client within doker container

$ sudo docker exec -it JayDevDB bash -c "source /home/oracle/.bashrc; sqlplus jaychu/welcome1@:1521/ORCL"

SQL> select status, instance_name from v$instance;

STATUS       INSTANCE_NAME
------------ ----------------
OPEN         ORCL

Ref:
https://yingclin.github.io/2018/create-oracle-docker-container.html
https://www.digitalocean.com/community/questions/how-to-fix-docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket
https://linuxconfig.org/how-to-retrieve-docker-container-s-internal-ip-address

沒有留言:

LinkWithin-相關文件

Related Posts Plugin for WordPress, Blogger...