Docker部署数据库 postgres ,oracle, sqlserver 等
postgres
执行命令:
docker run --name mypostgres -d -p 45432:5432 -e POSTGRES_PASSWORD=postgres postgres
连接 数据库:postgres 用户名:postgres 密码:postgres
oracle
https://zhuanlan.zhihu.com/p/578605180
默认启动容器方式
docker run -d -it -p 1521:1521 \
--name oracle11g \
--restart=always registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
持久化启动方式如下
docker run -d -it -p 1521:1521 \
--name oracle \
--restart=always \
--mount source=oracle_vol,target=/home/app/oracle/oradata registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
配置 oracle
点击查看代码
# 进入容器
docker exec -it 【容器id或名称】 bash
#.切换到root账户(默认进入之后是oracle账户) 输入密码:helowin(密码都是一样的)
su root
# 编辑环境变量
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
source /etc/profile 使配置生效
# 创建软链接
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
# 切换到oracle用户,登录sqlplus
su - oracle
sqlplus /nolog
conn /as sysdba
alter user system identified by YOUR_PASSWORD;
alter user sys identified by YOUR_PASSWORD;
alter profile default limit PASSWORD_LIFE_TIME UNLIMITED;
# 如果你懒得写可以直接复制下面的!
alter user system identified by 123456;
alter user sys identified by 123456;
alter user scott identified by 123456;
# 解锁用户
alter user scott account unlock; 如果报错就手打
# 创建用户(可选,根据需要)
# 用一个具有dba权限的用户登录(sysdba),然后输入以下语句
create user 用户名 identified by 密码;
grant connect,resource,dba to 用户名;
https://zhuanlan.zhihu.com/p/578605180
或
https://www.cnblogs.com/tiankx/p/14015851.html
使用navcat连接oracle , 注意 服务名/SID 选项,username && password 都是 dev

sqlserver
#创建文件夹
mkdir -p /home/app/mssql
#拉取
docker pull mcr.microsoft.com/mssql/server:2019-latest
#启动
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=lLuopan123." -u 0:0 -p 1433:1433 --name mssql -v /home/app/mssql:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2019-latest
#登入容器
docker exec -it mssql /bin/bash
#连接到sqlcmd
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Luopan123.'
#执行SQL语句创建数据库
CREATE DATABASE testDB
go
默认账号

浙公网安备 33010602011771号