Docker创建环境

试工具要多建几个环境,Docker创建环境一些记录

创建mysql

1
2
3
4
5
6
7
8
9
10
查看镜像
docker search mysql
拉取镜像
docker pull mysql
查看当前拥有的镜像
docker images
实例化镜像并运行
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql
查看正在运行的docker
docker ps

apt-get update 报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
root@c8e18cb28215:/etc/mysql# apt-get install
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@c8e18cb28215:/etc/mysql# apt-get update
Err:1 http://deb.debian.org/debian buster InRelease
Temporary failure resolving 'deb.debian.org'
Err:2 http://repo.mysql.com/apt/debian buster InRelease
Temporary failure resolving 'repo.mysql.com'
Err:3 http://security.debian.org/debian-security buster/updates InRelease
Temporary failure resolving 'security.debian.org'
Err:4 http://deb.debian.org/debian buster-updates InRelease
Temporary failure resolving 'deb.debian.org'
Reading package lists... Done
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://repo.mysql.com/apt/debian/dists/buster/InRelease Temporary failure resolving 'repo.mysql.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

修改DNS

1
echo "nameserver 8.8.8.8" | tee /etc/resolv.conf > /dev/null

重启docker!!

1
systemctl restart docker

外部主机无法访问docker中mysql容器

1
2
3
4
5
mysql> grant all privileges  on *.* to root@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

以下mysql版本可以成功连接

1
mysql  Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

以下版本会出现连接ssl错误

1
2
3
4
5
GlarcydeMacBook-Pro:blog glarcy$ mysql -V
mysql Ver 14.14 Distrib 5.7.26, for macos10.14 (x86_64) using EditLine wrapper
GlarcydeMacBook-Pro:blog glarcy$ mysql -h 192.168.x.x -uroot -p
Enter password:
ERROR 2026 (HY000): SSL connection error: unknown error number

查看mysql中的ssl配置

1
2
3
4
5
6
7
8
9
10
11
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW VARIABLES like '%ssl%';
+-------------------------------------+-----------------+
| Variable_name | Value |
+-------------------------------------+-----------------+
| have_openssl | YES |
| have_ssl | YES |

关闭ssl,修改/etc/mysql/my.cnf文件,添加如下配置

1
2
[mysqld]                                                                             
skip_ssl

重启docker,可以看到配置已被修改

1
2
3
4
5
6
mysql> SHOW VARIABLES like '%ssl%';
+-------------------------------------+----------+
| Variable_name | Value |
+-------------------------------------+----------+
| have_openssl | DISABLED |
| have_ssl | DISABLED |

认证插件错误

1
2
3
GlarcydeMacBook-Pro:blog glarcy$ mysql -h 192.168.x.x -uroot -p
Enter password:
ERROR 2061 (HY000): Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.

在MySQL8.0之前,身份验证的插件是mysql_native_password,在MySQL 8.0中,caching_sha2_password 是默认的身份验证插件,安全性更高。通过上面对插件caching_sha2_password的介绍,这次故障的原因可以猜测为:在从库连接主库的时候使用的是不被 caching_sha2_password认可的RSA公钥,所以主库MySQL拒绝了数据库连接的请求,从而,从库报错Authentication plugin ‘caching_sha2_password’ reported error: Authentication requires secure connection。

修改用户,使其不使用插件caching_sha2_password

创建SSH

1
2
3
4
docker pull hermsi/alpine-sshd
docker run -dit --name ssh -p 11022:22 --env ROOT_PASSWORD=123456 hermsi/alpine-sshd
连接
ssh root@localhost -p 11022

创建FTP

1
2
docker pull teezily/ftpd
docker run -dit --name ftp -p 11021:21 -e FTP_USER=admin -e FTP_PASSWORD=admin -e HOST=xxxx teezily/ftpd