Mac OS系统如何通过Docker安装Oracle11g
Docker基本概念
Docker 包括三个基本概念
- 镜像(Image)
- 容器(Container)
- 仓库(Repository)
先理解了这三个概念,就理解了 Docker 的整个生命周期。
Docker是一个跨平台的轻量级虚拟机,可移植性非常高,一次部署,终生可用。Docker可以在Linux,Windows,MacOS等平台上安装使用。我们都知道Linux有很多不同 的版本,例如Ubuntu,AIX,CentOS,Debian,Fedora,Oracle Linux,Red Hat Enterprise Linux,openSUSE and SUSE Linux Enterprise等。尽管Linux的版本很多,但是我们的Docker都可以在他们在面运行。你也可以使用Docker云来自动准备和管理你的云实例。
1.在Mac系统上安转Docker
Docker的Mac系统上的安装包中包含了你在Mac上运行Docker的所有依赖的东西,下面这个主题是描述在Mac系统上预安装需要考虑的一些问题和怎样在Mac系统上安装 Docker。
你的Mac本上是否已经安装了Docker,如果已经安装了Docker,你可以直接去启动Docker,如果你已经掌握了在Mac上使用Docker,那么你可以直接跳过整个Mac上的Docker的安装和运行部分。
1.2.在Mac下载Docker
在Mac系统上下载Docker有两种方式,一种是下载stable Docker,另一种是下载Beta版本的Docker
1.3.stable Docker下载
稳定版的Docker是完全测试过的,并且在Docker引擎中带有实验特征的最新版本的Docker引擎,这种引擎在默认情况下启用并其在Docker Daemon设置中优先配置为实验模式。如果你想依赖平台来工作那么这种安装方式是最好的选择。这些版本遵循比beta版更长的发布时间版本计划,与Docker Engine版本和修补程序同步。在稳定通道上,您可以选择是否发送使用统计信息和其他数据。
下载地址:
https://download.docker.com/mac/stable/Docker.dmg
1.4.Mac上安装和运行Docker
安装
双击Docker.dmg打开安装包,然后拖拽Moby蓝鲸到应用文件夹。在安装过程中你将会被Docker.app请求输入你电脑的系统密码。给予进入特权的需要安装网络组件和链接到Docker应用程序。
运行
双击Docker.app启动Docker
Docker Desktop id running 恭喜你,你已经完成Mac下面的Docker安装
1.5.Mac平台下Docker相关
docker相关命令
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/Users/hjma/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with
"docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/Users/hjma/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/Users/hjma/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/Users/hjma/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
docker ps
查看正在运行的容器
hjmadeMacBook-Air:/ hjma$ docker ps
CONTAINER ID IMAGE ##### docker stop
停止正在运行的容器
docker start
启动容器
docker ps -a
查看终止状态的容器
docker rm -f webserver
移除正在运行的容器
docker rmi
删除的镜像
docker --version
查看docker的版本号,包括客户端、服务端、依赖的Go等
hjmadeMacBook-Air:/ hjma$ docker --version
Docker version 19.03.13, build 4484c46d9d
hjmadeMacBook-Air:/ hjma$ docker version
Client: Docker Engine - Community
Cloud integration 0.1.18
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 16:58:31 2020
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:07:04 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.3.7
GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
docker info
查看系统(docker)层面信息,包括管理的images, containers数等
1.5.1Docker搜索 Oracle镜像
1)Docker是一个容器,在容器内部存在很多镜像文件,通过具体的镜像文件可以运行具体的容器。要想在Docker中安装Oracle镜像,我们首先应该在Docker的远程仓库中进行搜索,因为Docker没有自带Oracle相关镜像,命令如下(根据你Mac的实际情况决定是否要加sudo):
docker search docker-oracle-xe-11g
hjmadeMacBook-Air:/ hjma$ docker search docker-oracle-xe-11g
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
deepdiver/docker-oracle-xe-11g 34 [OK]
epiclabs/docker-oracle-xe-11g Customized Oracle XE 11g build for CI and de… 17 [OK]
pengbai/docker-oracle-xe-11g-r2 oracle xe 11g r2 with sql initdb and web con… 9 [OK]
arahman/docker-oracle-xe-11g phusion/baseimage based spin off of alexei-l… 9 [OK]
konnecteam/docker-oracle-xe-11g Fork of https://github.com/wnameless/docker-… 3 [OK]
rafaelri/docker-oracle-xe-11g Fork from wnameless/docker-oracle-xe-11g 3 [OK]
ignatov/docker-oracle-xe-11g Dockerfile of Oracle Database Express Editio… 3 [OK]
rdehuyss/docker-oracle-xe-11g Oracle Express 11g R2 on Ubuntu 14.04.2 LTS 0 [OK]
jeromefromcn/docker-oracle-xe-11g docker-oracle-xe-11g 0 [OK]
lynxsolutions/docker-oracle-xe-11g docker-oracle-xe-11g 0 [OK]
zzzfree/docker-oracle-xe-11g docker-oracle-xe-11g 0 [OK]
gswteam/docker-oracle-xe-11g Oracle XE 11g 0 [OK]
deadok22/docker-oracle-xe-11g docker-oracle-xe-11g 0
deradam/docker-oracle-xe-11g Oracle Express Edition 11g Release 2 on Ubun… 0
bizybot/docker-oracle-xe-11g wnameless/docker-oracle-xe-11g 0 [OK]
dbanttari/docker-oracle-xe-11g Branch of wnameless/docker-oracle-xe-11g tha… 0 [OK]
nguoianphu/docker-oracle-xe-11g Oracle Express Edition 11g Release 2 on Ubun… 0 [OK]
xtechnologies/docker-oracle-xe-11g docker-oracle-xe-11g 0 [OK]
cheyu0325/docker-oracle-xe-11g docker-oracle-xe-11g 0
kikicarbonell/docker-oracle-xe-11g Docker image of Oracle Database Express Edit… 0 [OK]
demers/docker-oracle-xe-11g-spark Oracle XE 11g with Spark 0
ceagan/docker-oracle-xe-11g Modified version of wnameless/docker-oracle-… 0 [OK]
zigac/docker-oracle-xe-11g Oracle xe 11g 0 [OK]
gmartsenkov/docker-oracle-xe-11g oracle 0 [OK]
dockerbolcom/docker-oracle-xe-11g Fork of https://github.com/wnameless/docker-… 0 [OK]
1.5.2Docker拉取Oracle镜像
我们选择第一个STAR最多的一个镜像进行安装,拉取镜像命令如下:
docker pull deepdiver/docker-oracle-xe-11g
hjmadeMacBook-Air:/ hjma$ docker pull deepdiver/docker-oracle-xe-11g
Using default tag: latest
latest: Pulling from deepdiver/docker-oracle-xe-11g
Image docker.io/deepdiver/docker-oracle-xe-11g:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
a3ed95caeb02: Pulling fs layer
9cf7e98c567b: Pulling fs layer
d2ff49536f4d: Pulling fs layer
f94adccdbb9c: Pulling fs layer
ee950bf8af06: Pulling fs layer
eec0023b823a: Pulling fs layer
2bbcf2933a57: Pull complete
1d639c2160a1: Pull complete
2631aa3055c3: Pull complete
d859f4b0261f: Pull complete
344fe8edcc0a: Pull complete
48fec8d59976: Pull complete
c9c81ef7960f: Pull complete
7e928eb7228a: Pull complete
56e977b47ad6: Pull complete
5c896b34601c: Pull complete
bcab6dcbd345: Pull complete
42e031cc37c0: Pull complete
fd6c6b47d0ba: Pull complete
546a383ffbe3: Pull complete
5acead7005d0: Pull complete
206b7448a401: Pull complete
bdf584565438: Pull complete
4ce7a34d8c4b: Pull complete
8702b3ee1143: Pull complete
777d696e58cd: Pull complete
8271d90e318b: Pull complete
c0e2d1590154: Pull complete
aeb67e38d18e: Pull complete
Digest: sha256:30c9b1f61397bbca016c25b21c4c2e5399af225306e41272874411ae2bd741d3
Status: Downloaded newer image for deepdiver/docker-oracle-xe-11g:latest
docker.io/deepdiver/docker-oracle-xe-11g:latest
1.5.3 Oracle镜像转成容器并使用该容器
等待镜像下载完毕就可。待镜像下载完毕之后,我们需要将该镜像转成容器并使用该容器,命令如下:
docker run -d -p 1521:1521 --name oracle11g deepdiver/docker-oracle-xe-11g
hjmadeMacBook-Air:/ hjma$ docker run -d -p 1521:1521 --name oracle11g deepdiver/docker-oracle-xe-11g
f280f8cf651bd0e1463ed4ff9928fdb1222903dfdf030ddb5d7b511c2ffc95bf
hjmadeMacBook-Air:/ hjma$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f280f8cf651b deepdiver/docker-oracle-xe-11g "/bin/sh -c 'sed -i …" 3 minutes ago Up 3 minutes 22/tcp, 8080/tcp, 0.0.0.0:1521->1521/tcp oracle11g
2)在Oracle容器中简单配置你的Oracle数据库并通过Navicat进行连接
进入容器内部的命令如下:
sudo docker exec -it 你的容器Id(可通过docker ps命令获得) /bin/bash
hjmadeMacBook-Air:~ root# docker exec -it f280f8cf651b /bin/bash
root@f280f8cf651b:/#
通过sqlplus进入Oracle:
sqlplus system/oracle
root@f280f8cf651b:/# sqlplus system/oracle
SQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 25 08:26:26 2020
Copyright (c) 1982, 2011, Oracle. All rights reserved.
ERROR:
ORA-28002: the password will expire within 7 days
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> select username,password from dba_users;
USERNAME PASSWORD
------------------------------ ------------------------------
SYS
ANONYMOUS
AUTOTEST
SYSTEM
APEX_PUBLIC_USER
APEX_040000
OUTLN
XS$NULL
FLOWS_FILES
MDSYS
CTXSYS
USERNAME PASSWORD
------------------------------ ------------------------------
XDB
HR
13 rows selected.
依次进行如下操作:
查看数据库用户名和密码:
select username,password from dba_users;
当然,你可以通过已经存在的用户名和密码来登录数据库,推荐使用新创建的用户来进行数据库的登录,sql如下:
SQL> create user user0435 identified by 123456;
User created.
创建完之后,可以通过如下sql进行验证:
SQL> select * from all_users;
USERNAME USER_ID CREATED
------------------------------ ---------- ---------
XS$NULL 2147483638 28-AUG-11
USER0435 49 25-OCT-20
AUTOTEST 48 25-OCT-20
APEX_040000 47 28-AUG-11
APEX_PUBLIC_USER 45 28-AUG-11
FLOWS_FILES 44 28-AUG-11
HR 43 28-AUG-11
MDSYS 42 28-AUG-11
ANONYMOUS 35 28-AUG-11
XDB 34 28-AUG-11
CTXSYS 32 28-AUG-11
USERNAME USER_ID CREATED
------------------------------ ---------- ---------
OUTLN 9 28-AUG-11
SYSTEM 5 28-AUG-11
SYS 0 28-AUG-11
14 rows selected.
在创建完新用户之后,需要对该用户进行授权,该用户具有什么权限都是通过自己指定的,这也是为什么推荐使用自定义用户登录数据库的原因,sql如下:
SQL> grant dba to user0435;
Grant succeeded.
SQL> grant dba to user0436;
grant dba to user0436
*
ERROR at line 1:
ORA-01917: user or role 'USER0436' does not exist
connect表示具有连接数据库的权限;resource表示具有操作数据库的权限; dba管理员权限;
至此,所有需要配置的数据库配置都已经配置完毕,可以通过Navicat进行连接了,如下图所示:
几个需要注意的地方:
- 主机就是localhost或127.0.0.1
- 端口为docker内部Oracle容器映射到宿主机的端口,上述命令有将,我的是映射到1521端口
- 选择服务名进行连接,并且该版本Oracle数据库的服务名为XE(唯一)
- 角色选择默认就行
- 用户名和密码就是我们在上述创建的用户名和密码
Mac用Navicat连接Oracle数据库报ORA-21561: OID generation failed
yin138
码哥码哥yin138:后来者们注意了,这个问题不在于服务器的配置,而在于客户端(用navicat的电脑的hostname和/etc/hosts不一样)。2年前回复
点赞 qq_41973884 WithAtermisia回复: 好人一生平安,一直在服务器上改,没丁点反应。。。。 解决办法,修改
hostname 与 hosts 里保持一致,即在Mac的terminal终端中执行下面这条命令即可 而不是服务器中执行
hjmadeMacBook-Air:~ root# hostname
hjmadeMacBook-Air.local
hjmadeMacBook-Air:~ root# sudo scutil --set HostName localhost
hjmadeMacBook-Air:~ root# hostname
localhost
hjmadeMacBook-Air:~ root#
再次测试 连接成功
在配置完上述内容之后,点击连接测试,即可连接成功。