Docker安装MySQL

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值