Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。
Docker 项目的目标是实现轻量级的操作系统虚拟化解决方案。 Docker 的基础是 Linux 容器(LXC)等技术。
在 LXC 的基础上 Docker 进行了进一步的封装,让用户不需要去关心容器的管理,使得操作更为简便。用户操作 Docker 的容器就像操作一个快速轻量级的虚拟机一样简单。
Docker 的优点作为一种新兴的虚拟化技术,Docker 跟传统的虚拟机相比具有众多的优势。
一致的运行环境:Docker 的镜像提供了除内核外完整的运行时环境,确保了应用运行环境的一致性,从而不会再出现“这段代码在我机器上没问题啊”这类问题。
更快速的启动时间:可以做到秒级、甚至毫秒级的启动时间。大大的节约了开发、测试、部署的时间。
隔离性:避免公用的服务器,资源会容易受到其他用户的影响。
弹性伸缩,快速扩展:善于处理集中爆发的服务器使用压力。
更轻松的迁移:Docker 容器几乎可以在任意的平台上运行,包括物理机、虚拟机、公有云、私有云、个人电脑、服务器等。 这种兼容性可以让用户把一个应用程序从一个平台直接迁移到另外一个。
持续交付和部署:使用Docker可以通过定制应用镜像来实现持续集成、持续交付、部署。
2、安装docker我是虚拟机装的Centos7,linux 3.10 内核,docker官方说至少3.8以上,建议3.10以上(ubuntu下要linux内核3.8以上, RHEL/Centos 的内核修补过, centos6.5的版本就可以——这个可以试试)
1,root账户登录,查看内核版本如下
[root@oracle ~]# uname -a Linux oracle 3.10.0-1160.49.1.el7.x86_64 #1 SMP Tue Nov 30 15:51:32 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
2,把yum包更新到最新(温馨提示:新环境或测试环境可随意操作,生产环境酌情慎重更新)
[root@localhost ~]# yum update 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.cn99.com base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 正在解决依赖关系 --> 正在检查事务 ---> 软件包 NetworkManager.x86_64.1.1.12.0-6.el7 将被 升级 ---> 软件包 NetworkManager.x86_64.1.1.12.0-10.el7_6 将被 更新
(期间要选择确认,输入 y 即可)
3,安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
[root@oracle ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本 软件包 device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 已安装并且是最新版本 软件包 7:lvm2-2.02.187-6.el7_9.5.x86_64 已安装并且是最新版本 无须任何处理
4,设置yum源(选择其中一个)
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央仓库)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)
[root@oracle ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 已加载插件:fastestmirror adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo
5,可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r 已加载插件:fastestmirror 可安装的软件包 * updates: mirrors.cn99.com Loading mirror speeds from cached hostfile * extras: mirrors.aliyun.com docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
6,安装Docker,命令:yum install docker-ce-版本号,我选的是docker-ce-18.03.1.ce,如下
[root@localhost ~]# yum install docker-ce-18.03.1.ce 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.cn99.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 docker-ce.x86_64.0.18.03.1.ce-1.el7.centos 将被 安装
(期间要选择确认,输入 y 即可)
7, 启动Docker,命令:systemctl start docker,设置开机启动,如下
[root@localhost ~]# systemctl start docker [root@localhost ~]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@localhost ~]# docker version Client: Version: 18.03.1-ce API version: 1.37 Go version: go1.9.5 Git commit: 9ee9f40 Built: Thu Apr 26 07:20:16 2018 OS/Arch: linux/amd64 Experimental: false Orchestrator: swarm Server: Engine: Version: 18.03.1-ce API version: 1.37 (minimum version 1.12) Go version: go1.9.5 Git commit: 9ee9f40 Built: Thu Apr 26 07:23:58 2018 OS/Arch: linux/amd64 Experimental: false3、docker安装Oracle11g
1、拉取 docker 镜像:
[root@localhost ~]# docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g Using default tag: latest latest: Pulling from helowin/oracle_11g ed5542b8e0e1: Pull complete a3ed95caeb02: Pull complete 1e8f80d0799e: Pull complete Digest: sha256:4c12b98372dfcbaafcd9564a37c8d91456090a5c6fb07a4ec18270c9d9ef9726 Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g:latest
该镜像由阿里云提供,大概6G左右,等待下载即可
2、用 docker images 命令查看镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g latest 3fa112fd3642 3 years ago 6.85GB
运行镜像
docker run -d -p 1521:1521 --name oracle registry.aliyuncs.com/helowin/oracle_11g
3、进入容器修改账号密码
3.1,检查容器是否运行成功
[root@localhost ~]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a151f9478f94 registry.aliyuncs.com/helowin/oracle_11g "/bin/sh -c '/home/o…" about a minute ago Up 30 seconds 0.0.0.0:1521->1521/tcp oracle
启动oracle
[root@localhost ~]# docker start oracle
3.2,进入容器:docker exec -it oracle bash
[root@localhost ~]# docker exec -it oracle bash [oracle@a151f9478f94 /]$
3.3,切换回root用户
[oracle@a151f9478f94 /]$ exit exit [root@localhost ~]#
3.4,编辑环境变量 vi /etc/profile 在文件的末尾添加一下内容
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2 export ORACLE_SID=helowin export PATH=$ORACLE_HOME/bin:$PATH
3.5,使得修改生效:
[root@localhost ~]# source /etc/profile
3.6,进入容器(此处的id就是第一个命令下的id),加载一下用户环境变量,进入容器后,自动是oracle用户
[root@localhost ~]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a151f9478f94 registry.aliyuncs.com/helowin/oracle_11g "/bin/sh -c '/home/o…" 3 hours ago Up 3 hours 0.0.0.0:1521->1521/tcp oracle [root@localhost ~]# docker exec -it a151f9478f94 /bin/bash [oracle@a151f9478f94 /]$ source ~/.bash_profile
[oracle@8cee27ec06a4 /]$ sqlplus /nolog SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 8 10:33:13 2021 Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn / as sysdba ## 使用sysdba 连接oracle,最大权限,os认证,只能在本机上登陆使用。 Connected. SQL> alter user system identified by system; ## 修改用户 system 的密码为 oracle ,可以自定义 User altered. SQL> alter user sys identified by sys; User altered. SQL> create user ETS identified by ETS; User created. SQL> grant connect,resource,dba to ETS ; Grant succeeded.
在使用sysdba 连接oracle时我这里报错了,
SQL> conn / as sysdba Connected to an idle instance. SQL> alter user system identified by system; alter user system identified by system * ERROR at line 1: ORA-01012: not logged on Process ID: 0 Session ID: 0 Serial number: 0
docker安装oracle出现错误:ORA-01012: not logged on
需要先关闭Oracle,然后重新启动
SQL> shutdown abort ORA-03113: end-of-file on c" - rest of line ignored. SQL> startup ORACLE instance started. Total System Global Area 1603411968 bytes Fixed Size 2213776 bytes Variable Size 402655344 bytes Database Buffers 1191182336 bytes Redo Buffers 7360512 bytes Database mounted. Database opened. SQL> conn / as sysdba Connected. SQL> alter user system identified by system; User altered.
SQL> exit ##退出编辑SQL Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@a151f9478f94 /]$ exit ##回到root用户 exit [root@localhost ~]#4、连接 账号system密码system服务名helowin 5、docker-compose安装Oracle11g(持久化)
version: "3"
services:
oracle:
image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
container_name: oracle
privileged: true
environment:
- TZ=Asia/Shanghai
# volumes:
# - /opt/oracle/oradata:/home/oracle/app/oracle/oradata
# - /opt/oracle/flash_recovery_area/helowin:/home/oracle/app/oracle/flash_recovery_area/helowin
ports:
- "1521:1521"



