在Mac上安装docker并部署oracle 12.2

其实很早就想写这篇,但是由于工作忙,一直没有来得整理出来。趁着周末,发布出来吧。

在本文中,你将看到:

1. 在Mac上安装docker,并启动docker
2. 部署oracle docker的build file,并创建image
3. 部署oracle软件在docker中
4. 安装oracle实例在docker中
5. 启动,停止docker以及如何连接数据库

一。在Mac上安装docker。
到docker store下载即可。下载地址是:https://store.docker.com/editions/community/docker-ce-desktop-mac
其实我们还可以看到别的操作系统的版本,如centos版本,aws版本,Ubuntu版本等等,在centos上,可以用wget命令进行下载。在这里我们用到的是mac版本。

下载完成后,我们得到116M左右的Docker.dmg文件,点击拖动到application文件夹进行安装。

安装完成后,你就可以在launchpad中看到docker图标,点击打开:

适当调整一下cpu内存分配,如给一半资源,4个CPU,16G内存。注意这里也可以看到了你的container image的位置在哪里,点击move可以挪到别的位置去。

启动之后,你就可以在终端敲docker info检查了。

其实安装完docker之后,你可以在docker store中直接pull oracle database 12c(12.1.0.2版本)

但是一方面这个版本是oracle 12.1版本,不是最新的12.2版本,另一方面数据库是包含在container中,如果删除container,就也一并删除了database,这不是我们所想要的。我们选择将container和database的数据文件分开。

二、部署oracle docker的build file,并创建image
到github下载oracle的build file:docker-images-master.zip,地址是https://github.com/oracle/docker-images,是一个约5M的文件。

下载完成后,找个目录解压。如我是放在/Users/[username]/iDocker 下。

然后到otn下载oracle 12.2的安装介质linuxx64_12201_database.zip。下载地址是:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html,是一个3.2G的文件。

下载完成后,将安装介质放在docker-images-master解压之后的目录下:/Users/[username]/idocker/docker-images-master/OracleDatabase/dockerfiles/12.2.0.1,即:

三、部署oracle软件在docker中
很简单,就一条命令:

需要注意的时候,在安装过程中需要联网,因为他会下载oraclelinux:7-slim和yum install pre-install的包。

附件是完整的log:build.log

安装完成这一步后,我们就可以用docker images命令看我们的安装情况了:
可以看到oracle linux和oracle database软件已经被装好。


四、安装oracle实例在docker中

安装数据库实例,也只需要一条命令:

注意数据文件已经map到/Users/[username]/oradata下。此时就算你删除了container,这些数据文件还是会被保留的。
对应的log如下,注意到了最后,会停在那里,估计run命令最后调用类似docker logs -f oracle这样的命令,会tail -f类似的输出,所以我们可以直接在别的窗口docker stop oracle再docker start oracle。

完整的log:run.log

如果“DATABASE IS READY TO USE!”字样已经出现,且后面的log一直停着不动,可以在别的窗口重启container:

五、启动,停止docker以及如何连接数据库
到了最关心的部分,如何docker和连接数据库。
启停docker其实我们在上一步已经操作过,即:

如果要看alertlog,可以:

后者是以tail -f的方式查看的。

连接数据库,注意我们一开始创建的数据库,密码是:

我们可以通过如下命令来修改密码:

然后我们可以用Navicat这个Mac上最流行的客户端,连接oracle数据库。

另外,如果你想进入container,以传统的方式管理数据库,你可以这样:
先用docker ps -a查询出container的container id,再用docker exec -it [container id] /bin/bash 连接:

参考:
https://sqlmaria.com/2017/04/27/oracle-database-12c-now-available-on-docker/
http://www.eygle.com/archives/2017/05/mac_docker_oracle_122.html

相关文章

14条评论

  1. 大神晚上好,依照你的教程我用docker装好了oracle,只是idea用sys连接数据库时提示必须要sysdba角色才能登陆,然而我想试一下scott登陆但又不知道怎么解锁。请问你是怎样用idea连接docker装的oracle的。

  2. 在docker中先直接登录数据库主机,然后sqlplus ‘/ as sysdba’;然后 alter user scott account unlock;即可解锁scott用户。

    ps:我不用idea。

  3. 报错, 请问如何处理
    Step 7/17 : RUN chmod ug+x $INSTALL_DIR/*.sh && sync && $INSTALL_DIR/$CHECK_SPACE_FILE && $INSTALL_DIR/$SETUP_LINUX_FILE
    —> Running in 72f8c1fc6b44
    Loaded plugins: ovl
    http://yum.oracle.com/repo/OracleLinux/OL7/UEKR4/x86_64/repodata/updateinfo.xml.gz: [Errno -1] Metadata file does not match checksum
    Trying other mirror.
    http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/repodata/comps.xml: [Errno -1] Metadata file does not match checksum
    Trying other mirror.
    http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/repodata/updateinfo.xml.gz: [Errno -1] Metadata file does not match checksum
    Trying other mirror.
    http://yum.oracle.com/repo/OracleLinux/OL7/UEKR4/x86_64/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum
    Trying other mirror.
    http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum
    Trying other mirror.
    http://yum.oracle.com/repo/OracleLinux/OL7/UEKR4/x86_64/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum
    Trying other mirror.

    One of the configured repositories failed (Latest Unbreakable Enterprise Kernel Release 4 for Oracle Linux 7Server (x86_64)),
    and yum doesn’t have enough cached data to continue. At this point the only
    safe thing yum can do is fail. There are a few ways to work “fix” this:

    1. Contact the upstream for the repository and get them to fix the problem.

    2. Reconfigure the baseurl/etc. for the repository, to point to a working
    upstream. This is most often useful if you are using a newer
    distribution release than is supported by the repository (and the
    packages for the previous distribution release still work).

    3. Run the command with the repository temporarily disabled
    yum –disablerepo=ol7_UEKR4 …

    4. Disable the repository permanently, so yum won’t use it by default. Yum
    will then just ignore the repository until you permanently enable it
    again or use –enablerepo for temporary usage:

    yum-config-manager –disable ol7_UEKR4
    or
    subscription-manager repos –disable=ol7_UEKR4

    5. Configure the failing repository to be skipped, if it is unavailable.
    Note that yum will try to contact the repo. when it runs most commands,
    so will have to try and fail each time (and thus. yum will be be much
    slower). If it is a very temporary problem though, this is often a nice
    compromise:

    yum-config-manager –save –setopt=ol7_UEKR4.skip_if_unavailable=true

  4. 大神你好,step11报错请问怎么处理?

    Step 11/17 : RUN $ORACLE_BASE/oraInventory/orainstRoot.sh && $ORACLE_HOME/root.sh && rm -rf $INSTALL_DIR
    —> Running in fb634817431f
    /bin/sh: /opt/oracle/oraInventory/orainstRoot.sh: No such file or directory
    Removing intermediate container fb634817431f
    The command ‘/bin/sh -c $ORACLE_BASE/oraInventory/orainstRoot.sh && $ORACLE_HOME/root.sh && rm -rf $INSTALL_DIR’ returned a non-zero code: 127

    ERROR: Oracle Database Docker Image was NOT successfully created.
    ERROR: Check the output and correct any reported problems with the docker build operation.

  5. 大神,按照你的博客安装了oracle12c,想知道docker内部主机的root密码是什么

  6. Users/[username]/idocker/docker-images-master/OracleDatabase/ 根目录下面没有dockerfiles这个文件夹 要自己建吗? 谢谢大神。

    1. 新版的docker-images-master,已经转移到了/Users/[username]/iDocker/docker-images-master/OracleDatabase/SingleInstance/dockerfiles/12.2.0.1目录了

      1. 已经放好了 但是敲./buildDockerImage.sh -v 12.2.0.1 -e 部署不了

        1. 部署为什么有24步啊 而且11步后面就下不了了。。。
          ERROR: Oracle Database Docker Image was NOT successfully created.

      2. 你好 我按这个方法装输入./buildDockerImage.sh -v 12.2.0.1 -e 后显示
        -bash: ./buildDockerImage.sh: No such file or directory 请问是怎么回事?

  7. ==========================
    Building image ‘oracle/database:12.2.0.1-ee’ …
    Sending build context to Docker daemon 3.454GB
    Step 1/22 : FROM oraclelinux:7-slim as base
    7-slim: Pulling from library/oraclelinux
    9a0b9cd2dfe6: Downloading [===========> ] 8.645MB/36.38MB

    一直卡在这里,是什么原因呢?

回复 wfcadd 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据