1 搜索mysql镜像
$ sudo docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 7929 [OK] mariadb MariaDB is a community-developed fork of MyS… 2646 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Create… 598 [OK] percona Percona Server is a fork of the MySQL relati… 421 [OK] zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 174 [OK] hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 110 zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 91 [OK] centurylink/mysql Image containing mysql. Optimized to be link… 60 [OK] centos/mysql-57-centos7 MySQL 5.7 SQL database server 49 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 49 [OK] mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 41 tutum/mysql Base docker image to run a MySQL database se… 31 schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 25 [OK] bitnami/mysql Bitnami MySQL Docker Image 25 [OK] zabbix/zabbix-web-apache-mysql Zabbix frontend based on Apache web-server w… 24 [OK] zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 20 [OK] linuxserver/mysql A Mysql container, brought to you by LinuxSe… 20 centos/mysql-56-centos7 MySQL 5.6 SQL database server 13 circleci/mysql MySQL is a widely used, open-source relation… 11 mysql/mysql-router MySQL Router provides transparent routing be… 8 openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6 jelastic/mysql An image of the MySQL database server mainta… 1 ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0 [OK] cloudposse/mysql Improved `mysql` service with support for `m… 0 [OK] widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 0 [OK]
2 下载mysql镜像
$ sudo docker pull centos/mysql-57-centos7
3 运行容器
$ sudo docker run -d -p 3306:3306 --name msyql -e MYSQL_ROOT_PASSWORD=123456 centos/mysql-57-centos7
命令说明:
--name mysql : 将容器的名字命名为mysql
-p 3306:3306 将容器的3306端口映射到主机的3306端口
-e MYSQL_ROOT_PASSWORD=123456 :初始化root用户的密码
-d : 以守护线程运行容器
centos/mysql-57-centos7 : 需要安装的镜像名称
4 查看容器启动情况
$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6ce6f5d818a9 centos/mysql-57-centos7 "container-entrypoin…" 8 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp mysql