我docker拉取mysql镜像时用的是latest,我该怎么看我的镜像版本是多少?可以通过以下三种方法查看

我docker拉取mysql镜像时用的是latest,我该怎么看我的镜像版本是多少?

在这里插入图片描述

方法一:查看 Docker 镜像标签

你可以查看 Docker 镜像的标签信息,了解当前使用的 MySQL 镜像版本。
具体步骤如下:

1. 列出本地 Docker 镜像:

docker images

输出类似于:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              6a2c6b4b4c8d        3 days ago          405MB

从输出中可以看到 mysql:latest 镜像的 IMAGE ID

2.查看具体的镜像标签

你可以查看该镜像的详细信息,包括标签和其他元数据:

docker inspect 6a2c6b4b4c8d

输出将是 JSON 格式的数据,其中包含了镜像的所有标签。通常情况下,MySQL 官方镜像会带有多个标签,包括具体的版本号,例如 5.7 或 8.0。

方法二:进入容器检查 MySQL 版本

在容器内部直接检查 MySQL 的版本。

1.获取容器的 ID 或名称:

docker ps

运行结果

C:\Users\Administrator>docker ps
CONTAINER ID   IMAGE                             COMMAND                   CREATED       STATUS       PORTS                               NAMES
ce174ae6c172   mysql                             "docker-entrypoint.s…"   8 weeks ago   Up 2 hours   0.0.0.0:3306->3306/tcp, 33060/tcp   mysqltest

从输出中获取容器的 ID 或名称(例如 mysqltest)。

2.进入 MySQL 容器:

docker exec -it mysqltest mysql -uroot -p

mysqltest 是容器名
mysql -uroot -p 是连接数据库;

运行命令结果如下

C:\Users\Administrator>docker exec -it mysqltest mysql -uroot -p
Enter password:

直接输入密码即可;
这里需要输入密码,我的密码是123465
这里你输入密码的动作是看不见的,不过没关系,直接输入即可;

运行命令结果如下

C:\Users\Administrator>docker exec -it mysqltest mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 178
Server version: 9.0.1 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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>

截图
在这里插入图片描述

3.检查 MySQL 版本

在 MySQL 命令行中输入以下命令来检查 MySQL 的版本:

SELECT VERSION();

运行结果如下

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 9.0.1     |
+-----------+
1 row in set (0.00 sec)

完整代码

C:\Users\Administrator>docker exec -it mysqltest mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 178
Server version: 9.0.1 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 9.0.1     |
+-----------+
1 row in set (0.00 sec)

mysql>

截图

在这里插入图片描述

方法三:使用数据库工具查看

  • 数据库工具连接数据库后,我的是Navicat Premium,
  • 连接好数据库,
  • 运行查询,
  • 输入命令:SELECT VERSION();
  • 截图如下:
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

橙-极纪元JJYCheng

客官,1分钱也是爱,给个赏钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值