使用docker镜像跑一个mysql

查找mysql镜像

[root@yhcookie ~]# docker search mysql
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                                                  MySQL is a widely used, open-source relation…   8147                [OK]                
mariadb                                                MariaDB is a community-developed fork of MyS…   2775                [OK]                
mysql/mysql-server                                     Optimized MySQL Server Docker images. Create…   607                                     [OK]
zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       192                                     [OK]
hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          113                                     
zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server wi…   101                                     [OK]
centurylink/mysql                                      Image containing mysql. Optimized to be link…   60                                      [OK]
centos/mysql-57-centos7                                MySQL 5.7 SQL database server                   53                                      
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          50                                      [OK]
mysql/mysql-cluster                                    Experimental MySQL Cluster Docker images. Cr…   44                                      
tutum/mysql                                            Base docker image to run a MySQL database se…   32                                      
zabbix/zabbix-web-apache-mysql                         Zabbix frontend based on Apache web-server w…   29                                      [OK]
schickling/mysql-backup-s3                             Backup MySQL to S3 (supports periodic backup…   27                                      [OK]
bitnami/mysql                                          Bitnami MySQL Docker Image                      26                                      [OK]
zabbix/zabbix-proxy-mysql                              Zabbix proxy with MySQL database support        22                                      [OK]
linuxserver/mysql                                      A Mysql container, brought to you by LinuxSe…   20                                      
centos/mysql-56-centos7                                MySQL 5.6 SQL database server                   13                                      
mysql/mysql-router                                     MySQL Router provides transparent routing be…   11                                      
circleci/mysql                                         MySQL is a widely used, open-source relation…   11                                      
openshift/mysql-55-centos7                             DEPRECATED: A Centos7 based MySQL v5.5 image…   6                                       
dsteinkopf/backup-all-mysql                            backup all DBs in a mysql server                6                                       [OK]
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]
[root@yhcookie ~]# 

拉取镜像

[root@yhcookie ~]# docker pull mysql:latest
latest: Pulling from library/mysql
743f2d6c1f65: Pull complete 
3f0c413ee255: Pull complete 
aef1ef8f1aac: Pull complete 
f9ee573e34cb: Pull complete 
3f237e01f153: Pull complete 
f9da32e8682a: Pull complete 
4b8da52fb357: Pull complete 
3416ca8f6890: Pull complete 
786698c2d5de: Pull complete 
4ddf84d07bd1: Pull complete 
cd3aa23461b6: Pull complete 
9f287a2a95ad: Pull complete 
Digest: sha256:711df5b93720801b3a727864aba18c2ae46c07f9fe33d5ce9c1f5cbc2c035101
Status: Downloaded newer image for mysql:latest
[root@yhcookie ~]# 

docker run -d --name mytest-mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:latest

--name ‘自定义的容器名’

MYSQL_ROOT_PASSWORD=‘自定义的root用户密码’

3306:3306 前者是你当前主机的3306端口,后者是当前容器中的3306端口。

运行一个容器

[root@yhcookie ~]# docker run --name mytest-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
b58c76de9b23ccc906925146a3925b26299fce20bb6aa3034fd4142696bd3e00

##进入容器

docker exec -it mytest-mysql /bin/bash 

[root@yhcookie ~]# docker exec -it mytest-mysql /bin/bash
root@b58c76de9b23:/# 

进入容器之后 就相当于进入了一个装有mysql的linux系统,可进行相应的操作,如:

root@b58c76de9b23:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.16 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值