本文共 1339 字,大约阅读时间需要 4 分钟。
从阿里云的Docker Hub 上pull一个MySQL的image.
docker pull registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7查看下载镜像
[root@hcdev yum.repos.d]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEregistry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 2 years ago 360MB名字太长,修改为短的tag
[root@hcdev yum.repos.d]# docker tag registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7 mysql:5.7[root@hcdev yum.repos.d]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmysql 5.7 ec7e75e5260c 2 years ago 360MBregistry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 2 years ago 360MB根据镜像创建容器
[root@hcdev yum.repos.d]# docker create -it mysql:5.7d625d3596ca386e57b047f7e4a50c78ba9330eb094a9ff6afd83a9daa02efd9c启动MySQL容器
[root@hcdev yum.repos.d]# docker run --name mtmysql -e MYSQL_ROOT_PASSWORD=chengce243 -d -i -p 3306:3306 mysql:5.75437d787164bf7174c71a64501151ed2132d030999a37a11c94fba13afcc8a36[root@hcdev yum.repos.d]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES5437d787164b mysql:5.7 "/entrypoint.sh mysq…" 8 seconds ago Up 7 seconds 0.0.0.0:3306->3306/tcp mtmysql进入MySQL终端
docker exec -it mtmysql mysql -uroot -pchengce243也可以
docker exec -it 5437d787164b mysql -uroot -pchengce243MySQL停止
docker stop mtmysql也可以
docker stop 5437d787164bMySQL启动
docker start mtmysql也可以
docker start 5437d787164b转载地址:http://aovta.baihongyu.com/