共计 3520 个字符,预计需要花费 9 分钟才能阅读完成。
最近使用云服务器,学习一下 Docker,今天学着使用 Docker 安装 MySQL。首先,从阿里云的 Docker Hub 上 pull 一个 MySQL 的 image.
[CentOS@linuxidc~]$ docker pull registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7
5.7: Pulling from acs-sample/mysql
d4bce7fd68df: Pull complete
a3ed95caeb02: Pull complete
01588229585e: Pull complete
ada32b818a1a: Pull complete
ac7528e308ac: Pull complete
44e3fb8779c7: Pull complete
bfcca86efc6a: Pull complete
32da415dff2e: Pull complete
aae6d9712a36: Pull complete
3148136ce9cc: Pull complete
Digest: sha256:32ff2f404c3bd199aaec2e6d19d91d59673e40d7394732124f91dd72a2e1ed97
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7
查看下载镜像,就会看到已经有了
[centos@linuxidc~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test/Ubuntu v1.0 523e7db0e264 11 minutes ago 98.3MB
ubuntu latest dd6f76d9cc90 7 days ago 122MB
hello-world latest 725dcfab7d63 8 days ago 1.84kB
registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 23 months ago 360MB
名字太长,修改为短的 tag
[centos@linuxidc~]$ docker tag registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7 mysql:5.7
[centos@linuxidc~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test/ubuntu v1.0 523e7db0e264 12 minutes ago 98.3MB
ubuntu latest dd6f76d9cc90 7 days ago 122MB
hello-world latest 725dcfab7d63 8 days ago 1.84kB
mysql 5.7 ec7e75e5260c 23 months ago 360MB
registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 23 months ago 360MB
根据镜像创建容器
[centos@linuxidc~]$ docker create -it mysql:5.7
62c975b37ad25b03914eb61e05088019f37ff9cb049a682ac02f20fac1761a4d
启动 MySQL 容器
[centos@linuxidc~]$ docker run –name mysqlserver -e MYSQL_ROOT_PASSWORD=sgcc -d -i -p 3306:3306 mysql:5.7
2a7a85124400be6fd47e0d97cf5d602456b1db1a11c6331747fe662481eea537
[centos@linuxidc~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2a7a85124400 mysql:5.7 “/entrypoint.sh my…” 9 seconds ago Up 8 seconds 0.0.0.0:3306->3306/tcp mysqlserver
188099665d1e ubuntu:latest “/bin/bash” 23 hours ago Up 23 hours angry_spence
进入 MySQL 终端
[centos@liujun ~]$ docker exec -it 2a7a85124400 /bin/bash
root@2a7a85124400:/# mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.9 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
更多 Docker 相关教程见以下内容:
Docker 安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm
Ubuntu 16.04 服务器上配置使用 Docker http://www.linuxidc.com/Linux/2017-06/145176.htm
Ubuntu 15.04 下安装 Docker http://www.linuxidc.com/Linux/2015-07/120444.htm
Docker 安装实例 http://www.linuxidc.com/Linux/2017-04/142666.htm
Docker 创建基础镜像 http://www.linuxidc.com/Linux/2017-05/144112.htm
在 Ubuntu 15.04 上如何安装 Docker 及基本用法 http://www.linuxidc.com/Linux/2015-09/122885.htm
Ubuntu 16.04 上 Docker 使用手记 http://www.linuxidc.com/Linux/2016-12/138490.htm
使用 Docker 分分钟启动常用应用 http://www.linuxidc.com/Linux/2017-04/142649.htm
Ubuntu 16.04 下 Docker 修改配置文件不生效解决办法 http://www.linuxidc.com/Linux/2017-05/143862.htm
Docker 的详细介绍:请点这里
Docker 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-11/148564.htm