Docker安装配置Mysql 8.0

作者: gavin 分类: Docker,未分类 发布时间: 2020-10-29 22:07

一、拉取镜像

root@ubuntudoc:~# docker pull mysql:8.0

二、查看镜像

root@ubuntudoc:~# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
mysql                     latest              9b51d9275906        10 days ago         547MB

三、运行Docker mysql镜像

docker run --restart=always -p 3306:3306 --name zsdmysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql

上述命令的参数,有如下含义:

  1. --name指定了你要取的名字。
  2. -p对应,需要映射出来的端口。比如:3306:3306,意识表示为zsdmysql的容器里面的3306端口对应我外面这个虚拟机的3306端口。
  3. -e是mysql的命令,设置root的密码为123456
  4. -d是运行的镜像,这里是mysql 容器镜像
  5. –restart=always 开机自动运行

四、查看当前容器

root@ubuntudoc:~# docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
3958ab15ea05        mysql               "docker-entrypoint.s…"   8 seconds ago       Up 6 seconds        0.0.0.0:3306->3306/tcp, 33060/tcp   zsdmysql

五、进入mysql

root@ubuntudoc:~# docker exec -it zsdmysql bash
### 下述代表容器里面的情况了
root@3958ab15ea05:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay          53G  3.7G   47G   8% /
tmpfs            64M     0   64M   0% /dev
tmpfs          1000M     0 1000M   0% /sys/fs/cgroup
/dev/dm-0        53G  3.7G   47G   8% /etc/hosts
shm              64M     0   64M   0% /dev/shm
tmpfs          1000M     0 1000M   0% /proc/acpi
tmpfs          1000M     0 1000M   0% /proc/scsi
tmpfs          1000M     0 1000M   0% /sys/firmware

root@3958ab15ea05:/# 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 8
Server version: 8.0.19 MySQL Community Server - GPL

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

来源:https://www.cnblogs.com/zhangshengdong/p/12502608.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注