Docker 创建MySQL容器

Docker 创建MySQL容器:

1.运行“docker pull mysql”获取mysql镜像

[root@centos7 mnt]# docker pull mysql
Using default tag: latest
Trying to pull repository docker.io/library/mysql ... 
latest: Pulling from docker.io/library/mysql
27833a3ba0a5: Pull complete 
864c283b3c4b: Pull complete 
cea281b2278b: Pull complete 
8f856c14f5af: Pull complete 
9c4f38c23b6f: Pull complete 
1b810e1751b3: Pull complete 
5479aaef3d30: Pull complete 
ded8fa2e1614: Pull complete 
636033ba4d2e: Pull complete 
902e6010661d: Pull complete 
dbe44d2bf055: Pull complete 
e906385f419d: Pull complete 
Digest: sha256:a7cf659a764732a27963429a87eccc8457e6d4af0ee9d5140a3b56e74986eed7
Status: Downloaded newer image for docker.io/mysql:latest

2.docker images查看本地的镜像:

 IMAGE ID  为 7bb2586065cd    的即刚才pull的MySQL镜像
 

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/mysql     latest              7bb2586065cd        3 hours ago         477 MB
centos              v1.1                28967a5f4c72        14 hours ago        298 MB

3.在后台启动mysql容器(--name指定了容器的名称,方便之后进入容器的命令行,MYSQL_ROOT_PASSWORD=tianyan指定了mysql的root密码,-d表示在后台运行)

[root@centos7 mnt]# docker run --name=mysql -it -p 33061:3306 -e MYSQL_ROOT_PASSWORD=tianyan -d 7bb2586065cd
1c41541d81089e30edc39f550aeaeb74caa3f000bd95d521c2098ef0e95cd445

4.查看新启动的myslq容器

[root@centos7 mnt]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                NAMES
1c41541d8108        7bb2586065cd        "docker-entrypoint..."   4 seconds ago       Up 3 seconds        33060/tcp, 0.0.0.0:33061->3306/tcp   mysql

5.进入mysql容器,进入myslq

[root@centos7 mnt]# docker exec -ti mysql /bin/bash
root@1c41541d8108:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 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>

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值