Install and configure Oracle12c in Docker and realize data persistence

Install and configure Oracle12c in Docker and realize data persistence

  • Press install Docker Ce in ubuntu

  • Getting oracle image information in docker

    $ docker search oracle
  • Select the image and pull it into the system. Make sure to configure acceleration first, or it will be super slow

    eric@userver:~$ docker pull sath89/oracle-12c
    Using default tag: latest
    latest: Pulling from sath89/oracle-12c
    863735b9fd15: Downloading   5.25MB/65.67MB
    4fbaa2f403df: Download complete 
    44be94a95984: Download complete 
    a3ed95caeb02: Download complete 
    b8bc6e8767ee: Download complete 
    c918da326197: Download complete 
    448e1619a038: Download complete 
    faadd00cf98e: Downloading  2.625MB/2.768GB
    94c8eec9fdf0: Download complete 
    58e66654f771: Downloading    1.3MB/4.437MB

  • View downloaded images

    eric@userver:~$ docker images
    sath89/oracle-12c latest 17cd1ab9d9a7 12 days ago 5.7GB
    hello-world    latest  f2a91732366c 4 weeks ago 1.85kB
  • List running containers

    #No running
    eric@userver:~$ docker ps

Creating containers with Oracle 12C

  • Mode 1: create a port and run it so that the data will not be retained every time you exit

    $ docker run -d -p 8080:8080 -p 1521:1521 sath89/oracle-12c
  • Mode 2: use data volume to effectively separate container and data and realize data persistence

    $ docker run -d -p 8080:8080 -p 1521:1521 -v /local_dir:/data sath89/oracle-12c
    #Parameter - d runs the container in the background and returns the container ID; - P specifies the port, - v specifies the data volume location
  • Features of data volume:

    1. Can be accessed by multiple containers, shared or reused directly

    2. Independent of the container cycle, the attached data volume will not be deleted when the container is deleted

    3. The data volume is initialized when the container starts. If the image used by the container contains data at the mount point, the data will be copied to the new container

    4. The contents of data volume can be modified directly

  • Data persistence

    eric@userver:~$ docker run -d -p 8080:8080 -p 1521:1521 -v /home/eric/oradata:/u01/app/oracle sath89/oracle-12c
    #View run container
    eric@userver:~$ docker ps
    CONTAINER ID     IMAGE                 COMMAND         
    7485d22f2fd5    sath89/oracle-12c   "/ "
    #Check the local directory and find an oradata directory
    #Create a new test file in this directory
    eric@userver:~/oradata$ sudo touch test.txt
    #Check whether the content in the container is new
    $ sudo docker exec 7485d22f2fd5 ls /u01/app/oracle
    #In fact, the data in the local volume is synchronized with that in the container
  • Delete container, data will not be deleted together

    $ docker stop 7485d22f2fd5
    $ docker rm 7485d22f2fd5
    $ ls oradata #Data still exists
    audit  checkpoints  diag  oradata   test.txt
  • Restart a container to mount the data volume

    $ sudo docker run -it --name oracle2 -v /home/eric/oradata:/datatest sath89/oracle-12c
    #--Name specifies a name. If it is not specified, a string of characters will be randomly assigned by default
    $ sudo docker exec oracle2 ls /data_test
    $ docker exec oracle2 ls /data_test
    ...    test.txt     ...
    #You can see the same data
    #Data persistence: every time the container is started, the data volume can be loaded
  • Run the container

    eric@userver:~$ docker exec -it 7485d22f2fd5 /bin/bash

Connecting to Oracle 12C

--Created with this image oracle User and password: systme/oracle|sys/oracle
port: 1521
sid: xe
service name: xe
username: system
password: oracle

--sqlplus connect:
root@7485d22f2fd5:/# sqlplus system/oracle@//localhost:1521/xe

SQL*Plus: Release Production on Wed Dec 20 06:25:21 2017
Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Standard Edition Release - 64bit PrSQL

SQL> -- Change password validity from 180 days to unlimited


Profile altered.
SQL> -- Unlock users
alter user SYSTEM account unlock

Tags: Oracle Docker sudo SQL

Posted on Thu, 30 Apr 2020 16:27:56 -0700 by jrd