docker安装mysql

  1. 创建文件夹mkdir -p /usr/local/docker/mysql
  2. 创建并启动一个mysql容器docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
  3. 复制文件到本地目录(不费事操作,直接映射my.cnf,保证本地先有这个文件)
    1. 配置文件(映射mysql.conf.d是由于mysql下的my.cnf是软链接,拷贝它没用)docker cp mysql:/etc/mysql/mysql.conf.d /usr/local/docker/mysql/conf
    2. 数据文件docker cp mysql:/var/lib/mysql /usr/local/docker/mysql/data
    3. 日志文件docker cp mysql:/var/log/mysql /usr/local/docker/mysql/log
  4. 删除这个容器docker stop mysql &&docker rm mysql
  5. 启动容器并挂载
docker run -p 3306:3306 --name mysql 
-v /usr/local/docker/mysql/conf:/etc/mysql/mysql.conf.d 
-v /usr/local/docker/mysql/logs:/var/log/mysql 
-v /usr/local/docker/mysql/data:/var/lib/mysql 
-e MYSQL_ROOT_PASSWORD=123456 
-d mysql:5.7
  1. 使用连接工具连接,建表,删除镜像,数据依旧存在
  2. docker-compose
    1. docker-compose.yml
      services:
          master:
              image: mysql:5.7
              container_name: mysql_compose
              ports:
                  - 3306:3306
              environment:
                  - MYSQL_ROOT_PASSWORD=123456
              volumes:
                  - ./data:/var/lib/mysql
                  - ./conf:/etc/mysql/conf.d
                  - ./log:/var/log/mysql
      
    2. 不配置挂载启动
    3. 复制
    4. 挂载启动

docker安装oracle原文链接

  1. 创建数据存储文件夹mkdir -p /data/oracle
  2. 切到文件夹下创建docker-composecd /data/oracle/
services:
  master:
    image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
    container_name: oracle
    ports:
      - 1521:1521
  1. 启动docker-compose up -d
  2. 进入容器docker exec -it oracle bash
    1. 环境变量初始化一下source /home/oracle/.bash_profile
    2. 登陆sqlplus /nolog,conn /as sysdba
    3. 修改system密码alter user system identified by system;
    4. 修改sys密码alter user sys identified by sys;
    5. 创建用户用户名test密码testcreate user test identified by test;
    6. 授权给testgrant connect,resource,dba to test;
    7. 修改密码永不过期(默认180天)ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
    8. 优化连接数alter system set processes=2000 scope=spfile;
  3. 测试连接
  4. 建个表,插入几条数据
  5. 退出到宿主机,将容器内的文件复制到宿主机docker cp oracle:/home/oracle/app/oracle/oradata/helowin/ /data/oracle/
  6. 更改所属用户chown -R 500.500 helowin
  7. 关闭容器docker-compose down
  8. 修改docker-compose.yml
services:
  master:
    image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
    container_name: oracle
    ports:
      - 1521:1521
    volumes:
      - ./helowin/:/home/oracle/app/oracle/oradata/helowin/
  1. 后台启动容器docker-compose up -d
  2. 进入容器docker exec -it oracle bash
    1. 刷新环境变量source /home/oracle/.bash_profile
    2. cp /home/oracle/app/oracle/oradata/helowin/control01.ctl /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl
    3. sqlplus / as sysdba
    4. shutdown immediate;
    5. startup
  3. 使用连接工具重新连接数据都在,数据都在/data/oracle/helowin

redis

redis:
    image: redis:5.0.14
    container_name: redis
    ports:
      - 6379:6379
    volumes:
    # 配置文件(保证./redis/conf/redis/redis.conf有此文件,默认的不会映射过来)
      - ./redis/conf/redis/redis.conf:/usr/local/etc/redis/redis.conf
    # 数据文件
      - ./redis/data:/data
内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/JaminYe/p/15558931.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!