合 WSL2中安装docker并快速构建多种数据库测试环境
Tags: OraclePGOSMSSQLSQL ServerMySQLDockerWindows 11WSL2体验快速数据库环境测试环境
WSL2中安装Docker服务
请参考:https://www.dbaup.com/wsl2zhonganzhuangdockerfuwu.html
效果:
使用CentOS 7.6环境
1 2 3 4 5 6 7 8 9 10 11 12 13 | docker run -d --name lhrcentos76 -h lhrcentos76 \ -p 227:22 -p 3387:3389 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true lhrbest/lhrcentos76:9.0 \ /usr/sbin/init root@lhrxxt:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c542bc126bbc lhrbest/lhrcentos76:9.0 "/usr/sbin/init" 11 days ago Up 7 seconds 0.0.0.0:227->22/tcp, :::227->22/tcp, 0.0.0.0:3387->3389/tcp, :::3387->3389/tcp lhrcentos76 root@lhrxxt:~# root@lhrxxt:~# docker exec -it lhrcentos76 bash [root@lhrcentos76 /]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) |
开启远程桌面mstsc
:
用户名:root
密码:lhr
完全可以运行Linux图形界面:
Oracle数据库
请参考:https://www.dbaup.com/dbbao37zaidockerzhongkuaisushiyonggegebanbencong10gdao19cdeoracleshu.html
https://www.dbaup.com/dbbao76zaidockerzhongzhixu2bujikeyongyouoracle-21chuanjing.html
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | root@lhrxxt:~# docker start lhroracle21c lhroracle21c root@lhrxxt:~# docker exec -it lhroracle21c bash [root@lhroracle21c /]# su - oracle Last login: Sun Sep 4 20:45:52 CST 2022 on pts/0 [oracle@lhroracle21c ~]$ sas SQL*Plus: Release 21.0.0.0.0 - Production on Tue Sep 13 15:07:53 2022 Version 21.3.0.0.0 Copyright (c) 1982, 2021, Oracle. All rights reserved. Connected to an idle instance. SYS@LHRCDB> startup ORACLE instance started. Total System Global Area 859829400 bytes Fixed Size 9692312 bytes Variable Size 532676608 bytes Database Buffers 310378496 bytes Redo Buffers 7081984 bytes Database mounted. Database opened. SYS@LHRCDB> show pbds SP2-0158: unknown SHOW option "pbds" SYS@LHRCDB> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PDB2 READ WRITE NO SYS@LHRCDB> exit Disconnected from Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production Version 21.3.0.0.0 [oracle@lhroracle21c ~]$ exit logout [root@lhroracle21c /]# exit exit root@lhrxxt:~# exit logout PS C:\Users\lhr\Desktop> wsl root@lhrxxt:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 68ef9ba74c02 lhrbest/oracle21c_ee_db_21.3.0.0 "/usr/sbin/init" 10 days ago Up 7 minutes 5502-5510/tcp, 0.0.0.0:1530->1521/tcp, :::1530->1521/tcp, 0.0.0.0:3400->3389/tcp, :::3400->3389/tcp, 0.0.0.0:5510->5500/tcp, :::5510->5500/tcp, 0.0.0.0:55100->5501/tcp, :::55100->5501/tcp lhroracle21c root@lhrxxt:~# |
PostgreSQL数据库
请参考:https://www.dbaup.com/dbbao69zaidockerzhongkuaisushiyonggegebanbendepostgresqlshujuku.html
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | root@lhrxxt:~# docker pull postgres:14.5 14.5: Pulling from library/postgres 7a6db449b51b: Pull complete b4f184bc0704: Pull complete 606a73c0d34a: Pull complete c39f1600d2b6: Pull complete 31f42f92b0fe: Pull complete c8b67d2b0354: Pull complete 31107b8480ee: Pull complete b26434cf8bfa: Pull complete 36220bd76bfa: Pull complete b79e75c4a0c2: Pull complete cc1ab699dda5: Pull complete 37312064dd9b: Pull complete 4bce56fcbfe5: Pull complete Digest: sha256:10e195b76c4e51f5a8c0c5686ce15c3d701f7f13c7003d50f40502b69c18fe5f Status: Downloaded newer image for postgres:14.5 docker.io/library/postgres:14.5 root@lhrxxt:~# docker run --name lhrpg14 -h lhrpg14 -d -p 54327:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:14.5 9395477ca203bc5f4b82f886e888a5724b22cddf051e528e00db68b281c53e25 root@lhrxxt:~# docker exec -it lhrpg14 bash root@lhrpg14:/# su - postgres postgres@lhrpg14:~$ psql psql (14.5 (Debian 14.5-1.pgdg110+1)) Type "help" for help. postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+------------+------------+----------------------- postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres + | | | | | postgres=CTc/postgres (3 rows) |
MySQL数据库
请参考:https://www.dbaup.com/zaidockerzhongkuaisushiyonggegebanbendemysqlshujuku.html
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | root@lhrxxt:~# docker run -d --name mysql8030 -h mysql8030 -p 3418:3306 \ > -v /etc/mysql/mysql8030/conf:/etc/mysql/conf.d \ > -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \ > mysql:8.0.30 f6e94a91fd69e26d0e9e7bd5b4ef11ecde0f4b8502299c537342141ea01bf80a root@lhrxxt:~# root@lhrxxt:~# cat > /etc/mysql/mysql8030/conf/my.cnf <<"EOF" > [mysqld] > default-time-zone = '+8:00' > log_timestamps = SYSTEM > skip-name-resolve > log-bin > server_id=80303418 > character_set_server=utf8mb4 > EOF root@lhrxxt:~# docker restart mysql8030 mysql8030 root@lhrxxt:~# docker exec -it mysql8030 bash bash-4.4# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) bash-4.4# mysql -uroot -plhr mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.30 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.05 sec) mysql> create database lhrdb; Query OK, 1 row affected (0.04 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | lhrdb | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) |