1.使用docker search mysql
查看可用版本
root@xiong-pc:/# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 12739 [OK]
mariadb MariaDB Server is a high performing open sou… 4888 [OK]
percona Percona Server is a fork of the MySQL relati… 579 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 555 [OK]
bitnami/mysql Bitnami MySQL Docker Image 71 [OK]
linuxserver/mysql-workbench 36
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 35
ubuntu/mysql MySQL open source fast, stable, multi-thread… 34
circleci/mysql MySQL is a widely used, open-source relation… 26
google/mysql MySQL server for Google Compute Engine 21 [OK]
rapidfort/mysql RapidFort optimized, hardened image for MySQL 13
vmware/harbor-db Mysql container for Harbor 10
bitnami/mysqld-exporter 3
ibmcom/mysql-s390x Docker image for mysql-s390x 2
nasqueron/mysql 1 [OK]
vitess/mysqlctld vitess/mysqlctld 1 [OK]
newrelic/mysql-plugin New Relic Plugin for monitoring MySQL databa… 1 [OK]
mirantis/mysql 0
docksal/mysql MySQL service images for Docksal - https://d… 0
drud/mysql-local-57 ddev mysql local container 0
drud/mysql 0
drud/mysql-docker-local-57 This repo has been deprecated, new tags are … 0
drud/mysql-docker-local docker containers for local womysql rk 0 [OK]
cimg/mysql 0
silintl/mysql-backup-restore Simple docker image to perform mysql backups… 0 [OK]
2.使用docker pull mysql
拉取官方最新版镜像
root@xiong-pc:/# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
3.查看本地镜像docker images
root@xiong-pc:/# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 3218b38490ce 5 months ago 516MB
redis latest 7faaec683238 8 months ago 113MB
hello-world latest feb5d9fea6a5 8 months ago 13.3kB
4.运行MySQL容器 docker run --name mysql -p 3306:3306 -v /opt/docker/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -d mysql
xiong@xiong-pc:$ docker run --name mysql -p 3306:3306 -v /opt/docker/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -d mysql
0401092b4399e33ccdcf3524db471fca310a78a7d87341e17600e520a8a4f900
参数说明:
- -name:后面是docker容器名
- -p 3306:3306:映射容器服务的3306端口到宿主机的3306端口,外部主机可以直接通过
宿主机ip:3306
访问到mysql服务。 - MYSQL_ROOT_PASSWORD=123456:设置MySQL服务root用户密码。
- -d:后面是镜像ID
- -v /opt/docker/mysql/conf:/etc/mysql/conf.d:将主机/opt/docker_v/mysql/conf目录挂载到容器的/etc/mysql/conf.d
5.使用docker ps
查看是否安装成功
xiong@xiong-pc:/$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0401092b4399 mysql "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql