1、拉取镜像 docker pull mysql/mysql-server:latest
Jeffrey@Jeffrey > ~/ > docker pull mysql/mysql-server:latest
latest: Pulling from mysql/mysql-server
78f907cdf4ab: Pull complete
035805736c03: Pull complete
d2d0a5329a4d: Pull complete
e550adc3fc8c: Pull complete
9d764ef2813b: Pull complete
6f9519148988: Pull complete
906914afa910: Pull complete
Digest: sha256:91170bd4e012f0bf46b5141a38b612427b37692e8465cdffe9b0ca2d74d37d8a
Status: Downloaded newer image for mysql/mysql-server:latest
mysql 全部都是 linux/amd64,m1芯片需要安装arm64版本,因此安装mysql-server,否则会报错“no matching manifest for linux/arm64/v8 in the manifest list entries
2、查看镜像 docker images
Jeffrey@Jeffrey > ~/ > docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php 7.3.33-fpm 91b1cacd3802 2 days ago 424MB
btpanel/btpanel lnmp 088a329cdb2f 3 weeks ago 3.56GB
nginx latest eeb9db34b331 2 months ago 134MB
tomcat latest b64abfdee99c 2 months ago 668MB
php latest c101545ce738 2 months ago 446MB
mysql latest 3218b38490ce 2 months ago 516MB
mysql/mysql-server latest 087c6f86492c 3 months ago 509MB
centos latest e6a0117ec169 5 months ago 272MB
3、启动容器 docker run --name=mysql -itd -e MYSQL_ROOT_PASSWORD=xxxxxx -p 3306:3306 mysql/mysql-server
Jeffrey@Jeffrey > ~/ > docker run --name=mysql -itd -e MYSQL_ROOT_PASSWORD=xxxxxx -p 3306:3306 mysql/mysql-server
3ee3dbe9f965547f22815ac3c3d2811d22efc4b96fae2261f7d1eb1065682ac2
Jeffrey@Jeffrey > ~/ > docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3ee3dbe9f965 mysql/mysql-server "/entrypoint.sh mysq…" 3 seconds ago Up 3 seconds (health: starting) 0.0.0.0:3306->3306/tcp, 33060-33061/tcp mysql
365e225e47a6 nginx "/docker-entrypoint.…" 43 hours ago Up 42 hours 0.0.0.0:8080->80/tcp myNginx
0c9b390a3e4f php:7.3.33-fpm "docker-php-entrypoi…" 43 hours ago Up 42 hours 9000/tcp php7.3
3、进入容器,登陆mysql,授权远程登录
#1、进入容器
docker exec -it mysql /bin/bash
#2、使用root账户登录
mysql -u root -p
#3、查看数据库
show databases;
#3、切换至mysql数据库
use mysql;
#4、查看用户权限
select host from user;
#5、将root用户授权更改为允许远程登录
update user set host='%' where user='root';
#6、刷新数据库,更新缓存
flush privileges;