Home > System Tutorial > LINUX > body text

Master explains how to install oracle and mysql with Docker under unbuntu

WBOY
Release: 2024-07-17 12:03:18
Original
708 people have browsed it

Master explains how to install oracle and mysql with Docker under unbuntu

1. Install docker

Update apt source and install CA certificate, the command is as follows:

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates
Copy after login

Add GPG key:

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Copy after login

Open the /etc/apt/sources.list.d/docker.list file (create one if it doesn’t exist)

Add source deb https://apt.dockerproject.org/repo ubuntu-xenial main and save

Select different sources according to system version:

On Ubuntu Precise 12.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-precise main

On Ubuntu Trusty 14.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-trusty main

Ubuntu Wily 15.10
deb https://apt.dockerproject.org/repo ubuntu-wily main

Ubuntu Xenial 16.04 (LTS)
deb https://apt.dockerproject.org/repo ubuntu-xenial main
Copy after login

Choose Ubuntu Xenial 16.04 (LTS) here

Update apt and make sure the source of Docker is correct

sudo apt-get update
apt-cache policy docker-engine
Copy after login

Installation:

sudo apt-get install docker-engine
Copy after login

Support ordinary users to use docker

The ppa installation docker group has been created, otherwise sudo groupadd docker will build it

sudo gpasswd -a ${USER} docker
sudo service docker restart
sudo chmod a+rw /var/run/docker.sock
Copy after login

docker search : Find oracle mirror from Docker Hub

$ docker search oracle
NAME                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
oraclelinux                         Oracle Linux is an open-source operating s...   398       [OK]       
frolvlad/alpine-oraclejdk8          The smallest Docker image with OracleJDK 8...   269                  [OK]
alexeiled/docker-oracle-xe-11g      This is a working (hopefully) Oracle XE 11...   221                  [OK]
sath89/oracle-12c                   Oracle Standard Edition 12c Release 1 with...   214                  [OK]
sath89/oracle-xe-11g                Oracle xe 11g with database files mount su...   133                  [OK]
isuper/java-oracle                  This repository contains all java releases...   55                   [OK]
jaspeen/oracle-11g                  Docker image for Oracle 11g database            54                   [OK]
oracle/glassfish                    GlassFish Java EE Application Server on Or...   30                   [OK]
oracle/openjdk                      Docker images containing OpenJDK Oracle Linux   25                   [OK]
airdock/oracle-jdk                  Docker Image for Oracle Java SDK (8 and 7)...   23                   [OK]
ingensi/oracle-jdk                  Official Oracle JDK installed on centos.        21                   [OK]
cogniteev/oracle-java               Oracle JDK 6, 7, 8, and 9 based on Ubuntu ...   20                   [OK]
wnameless/oracle-xe-11g             Dockerfile of Oracle Database Express Edit...   16                   [OK]
n3ziniuka5/ubuntu-oracle-jdk        Ubuntu with Oracle JDK. Check tags for ver...   14                   [OK]
oracle/nosql                        Oracle NoSQL on a Docker Image with Oracle...   13                   [OK]
collinestes/docker-node-oracle      A container with Node.js/Oracle instant cl...   9                    [OK]
andreptb/oracle-java                Debian Jessie based image with Oracle JDK ...   7                    [OK]
sgrio/java-oracle                   Docker images of Java 7/8 provided by Orac...   7                    [OK]
openweb/oracle-tomcat               A fork off of Official tomcat image with O...   7                    [OK]
flurdy/oracle-java7                 Base image containing Oracle's Java 7 JDK       5                    [OK]
davidcaste/debian-oracle-java       Oracle Java 8 (and 7) over Debian Jessie        3                    [OK]
teradatalabs/centos6-java8-oracle   Docker image of CentOS 6 with Oracle JDK 8...   3                    
spansari/nodejs-oracledb            nodejs with oracledb installed globally on...   1                    
publicisworldwide/oracle-core       This is the core image based on Oracle Lin...   1                    [OK]
sigma/nimbus-lock-oracle                                                            0                    [OK]
Copy after login
2. Pull oracle-oracle-xe-11g to the local
docker pull sath89/oracle-xe-11g
Copy after login
Display after

pull:

$ docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
hello-world            latest              f2a91732366c        8 days ago          1.85kB
sath89/oracle-xe-11g   latest              04851454491b        3 months ago        792MB
Copy after login

Create and start oracle instance:

docker run -d  -p 9090:8080 -p 1521:1521 -v /home/${USER}/oracle/data:/u01/app/oracle sath89/oracle-xe-11g
Copy after login

Where -p 9090:8080 is the Oracle Application Express web management port 8080 in the docker image mapped to the local 9090 port:

http://localhost:9090/apex
workspace: INTERNAL
user: ADMIN
password: oracle
Copy after login

-p 1521: 1521 is the oracle service port. If you don’t want to use 1521 for the local port, you can modify the first 1521.

3. Install oracle instant client instantclient:

Refer specifically to a previous blog post to create a streamlined version of the Oracle client and pro*c compilation environment under Ubuntu

I couldn’t find the 11g instantclient software on Oracle’s official website. I put it on Tianyi Cloud (access code: 6540)

Local configuration oracle SID:

Add in /opt/oracle/product/network/admin/tnsnames.ora (related to the instantclient path):

XE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = xe)
    )
  )
Copy after login

You can also go directly without configuring:

sqlplus sys/oracle@127.0.0.1:1521/xe as sysdba
sqlplus system/oracle@//localhost:1521/xe
Copy after login

Once configured, you can access it like this

sqlplus sys/oracle@xe as sysdba
sqlplus system/oracle@xe
Copy after login

sys and system are the two default users, one with sysdba authority and the other with system authority. The initial password is oracle

It is recommended to change the sys password immediately after successful installation

sqlplus sys/oracle@xe as sysdba
SQL>alter user sys identified by your-passwd
Copy after login

Create table space

SQL> create tablespace myts  datafile  '/u01/app/oracle/oradata/XE/myts.dbf'  size 100M autoextend on next 5M maxsize 400M;
Copy after login

Modify the system default tablespace

SQL>  alter database default tablespace MYTS;
SQL>  select a.property_name, a.property_value from database_properties a where a.property_name like '%DEFAULT%';

PROPERTY_NAME
--------------------------------------------------------------------------------
PROPERTY_VALUE
--------------------------------------------------------------------------------
DEFAULT_TEMP_TABLESPACE
TEMP

DEFAULT_PERMANENT_TABLESPACE
MYTS

DEFAULT_EDITION
ORA$BASE

.......
Copy after login

Create users, authorize and specify table spaces

SQL> create user scott identified by tiger;
SQL> grant connect, resource to scott;
SQL> alter user scott default tablespace myts;
Copy after login

Table creation script myscott.sql:

--------------------------------------------------------
--  File created - 星期六-六月-14-2014   
--------------------------------------------------------
--------------------------------------------------------
--  DDL for Table BONUS
--------------------------------------------------------

  CREATE TABLE "BONUS" 
   (	"ENAME" VARCHAR2(10), 
	"JOB" VARCHAR2(9), 
	"SAL" NUMBER, 
	"COMM" NUMBER
   ) ;
--------------------------------------------------------
--  DDL for Table DEPT
--------------------------------------------------------

  CREATE TABLE "DEPT" 
   (	"DEPTNO" NUMBER(2,0), 
	"DNAME" VARCHAR2(14), 
	"LOC" VARCHAR2(13)
   ) ;
--------------------------------------------------------
--  DDL for Table EMP
--------------------------------------------------------

  CREATE TABLE "EMP" 
   (	"EMPNO" NUMBER(4,0), 
	"ENAME" VARCHAR2(10), 
	"JOB" VARCHAR2(9), 
	"MGR" NUMBER(4,0), 
	"HIREDATE" DATE, 
	"SAL" NUMBER(7,2), 
	"COMM" NUMBER(7,2), 
	"DEPTNO" NUMBER(2,0)
   ) ;
--------------------------------------------------------
--  DDL for Table SALGRADE
--------------------------------------------------------

  CREATE TABLE "SALGRADE" 
   (	"GRADE" NUMBER, 
	"LOSAL" NUMBER, 
	"HISAL" NUMBER
   ) ;

---------------------------------------------------
--   DATA FOR TABLE BONUS
--   FILTER = none used
---------------------------------------------------
REM INSERTING into BONUS

---------------------------------------------------
--   END DATA FOR TABLE BONUS
---------------------------------------------------


---------------------------------------------------
--   DATA FOR TABLE DEPT
--   FILTER = none used
---------------------------------------------------
REM INSERTING into DEPT
Insert into DEPT (DEPTNO,DNAME,LOC) values (10,'ACCOUNTING','NEW YORK');
Insert into DEPT (DEPTNO,DNAME,LOC) values (20,'RESEARCH','DALLAS');
Insert into DEPT (DEPTNO,DNAME,LOC) values (30,'SALES','CHICAGO');
Insert into DEPT (DEPTNO,DNAME,LOC) values (40,'OPERATIONS','BOSTON');

---------------------------------------------------
--   END DATA FOR TABLE DEPT
---------------------------------------------------


---------------------------------------------------
--   DATA FOR TABLE EMP
--   FILTER = none used
---------------------------------------------------
REM INSERTING into EMP
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7369,'SMITH','CLERK',7902,to_timestamp('17-12月-80 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),800,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7499,'ALLEN','SALESMAN',7698,to_timestamp('20-2月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1600,300,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7521,'WARD','SALESMAN',7698,to_timestamp('22-2月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1250,500,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7566,'JONES','MANAGER',7839,to_timestamp('02-4月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2975,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7654,'MARTIN','SALESMAN',7698,to_timestamp('28-9月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1250,1400,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7698,'BLAKE','MANAGER',7839,to_timestamp('01-5月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2850,null,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7782,'CLARK','MANAGER',7839,to_timestamp('09-6月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2450,null,10);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7788,'SCOTT','ANALYST',7566,to_timestamp('19-4月 -87 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),3000,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7839,'KING','PRESIDENT',null,to_timestamp('17-11月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),5000,null,10);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7844,'TURNER','SALESMAN',7698,to_timestamp('08-9月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1500,0,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7876,'ADAMS','CLERK',7788,to_timestamp('23-5月 -87 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1100,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7900,'JAMES','CLERK',7698,to_timestamp('03-12月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),950,null,30);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7902,'FORD','ANALYST',7566,to_timestamp('03-12月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),3000,null,20);
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7934,'MILLER','CLERK',7782,to_timestamp('23-1月 -82 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1300,null,10);

---------------------------------------------------
--   END DATA FOR TABLE EMP
---------------------------------------------------


---------------------------------------------------
--   DATA FOR TABLE SALGRADE
--   FILTER = none used
---------------------------------------------------
REM INSERTING into SALGRADE
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (1,700,1200);
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (2,1201,1400);
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (3,1401,2000);
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (4,2001,3000);
Insert into SALGRADE (GRADE,LOSAL,HISAL) values (5,3001,9999);

---------------------------------------------------
--   END DATA FOR TABLE SALGRADE
---------------------------------------------------


--------------------------------------------------------
--  DDL for Index PK_EMP
--------------------------------------------------------

  CREATE UNIQUE INDEX "PK_EMP" ON "EMP" ("EMPNO") 
  ;
--------------------------------------------------------
--  DDL for Index PK_DEPT
--------------------------------------------------------

  CREATE UNIQUE INDEX "PK_DEPT" ON "DEPT" ("DEPTNO") 
  ;



--------------------------------------------------------
--  Constraints for Table EMP
--------------------------------------------------------

  ALTER TABLE "EMP" ADD CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") ENABLE;

--------------------------------------------------------
--  Constraints for Table DEPT
--------------------------------------------------------

  ALTER TABLE "DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") ENABLE;

--------------------------------------------------------
--  Ref Constraints for Table EMP
--------------------------------------------------------

  ALTER TABLE "EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
	  REFERENCES "DEPT" ("DEPTNO") ENABLE;
Copy after login

Execute scripts and queries:

SQL> @myscott.sql
SQL> select * from EMP;
Copy after login
4. Execute sqlplus directly in docker without installing the client:
$ docker ps -a
CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS                                            NAMES
3c6a2c2761fb        sath89/oracle-xe-11g   "/entrypoint.sh "   2 minutes ago       Up About a minute   0.0.0.0:1521->1521/tcp, 0.0.0.0:9090->8080/tcp   dreamy_pasteur
$ docker exec -it 3c6a2c2761fb /bin/bash
root@3c6a2c2761fb:/# su oracle
oracle@3c6a2c2761fb:/$ $ORACLE_HOME/bin/sqlplus / as sysdba

SQL*Plus: Release 11.2.0.2.0 Production on Wed Nov 29 13:40:15 2017

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> quit
Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
oracle@8e1a86793036:/$ $ORACLE_HOME/bin/sqlplus scott/tiger

SQL*Plus: Release 11.2.0.2.0 Production on Wed Nov 29 13:40:24 2017

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> select * from emp;

     EMPNO ENAME      JOB	       MGR HIREDATE	    SAL       COMM
---------- ---------- --------- ---------- --------- ---------- ----------
    DEPTNO
----------
      7369 SMITH      CLERK	      7902 17-DEC-80	    800
	20

......
Copy after login
5. Stop and start the oracle instance in the container
$ docker stop 3c6a2c2761fb
$ docker start 3c6a2c2761fb
Copy after login

To facilitate subsequent management, you can add alias in .bashrc

alias orastartdock='docker start 3c6a2c2761fb'
alias orastopdock='docker stop 3c6a2c2761fb'
Copy after login

Also available at

docker run -d --name=oracle1 -p 9090:8080 -p 1521:1521 -v /home/${USER}/oracle/data:/u01/app/oracle sath89/oracle-xe-11g
Copy after login

Specify the container name oracle1, which can be used to stop and start the instance in the following ways:

$ docker stop oracle1
$ docker start oracle1
Copy after login

Instead of using the CONTAINER ID randomly generated by docker

You can use ~$ docker rename oracle1 ora1 to rename the docker container name, use ~$docker rm container name or container ID to delete, or you can use the following command to delete them all

docker rm $(docker ps -aq)
Copy after login

Of course, it cannot be deleted when it is started.

As long as the port and data storage path are changed, one image can create multiple oracle instances, such as:

docker run -d --name=oracle2 -p 9092:8080 -p 1522:1521 -v /home/${USER}/oracle/data2:/u01/app/oracle sath89/oracle-xe-11g


docker run -d --name=ora3 -p 9093:8080 -p 1523:1521 -v /home/${USER}/oracle/data3:/u01/app/oracle sath89/oracle-12c
Copy after login

This way you can easily set up multiple oracle environments.

6. Run mysql
$docker pull mysql:5.7.20

$docker run -p 3307:3306 --name mysql5.7.20 -v /home/${USER}/mysqldata/mysql5.7.20/conf:/etc/mysql/conf.d -v /home/${USER}/mysqldata/mysql5.7.20/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.20

$ docker exec -it mysql5.7.20 bash

# mysql -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH  GRANT OPTION; 
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> FLUSH   PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
root@657aaa1203f4:/# exit
exit
~$ mysql -h 127.0.0.1   -P3307 -u root -123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement
mysql> quit
 
Copy after login

You must add -h 127.0.0.1 here, otherwise even if the port -P3307 is specified, it will still be connected to the mysql of the host machine instead of the one of the docker container. This is because the 3306 port is specified in .my.cf on the host machine.

The above is the detailed content of Master explains how to install oracle and mysql with Docker under unbuntu. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!