从阿里云的Docker Hub 上pull一个MySQL的image.
docker pull registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7
查看下载镜像
[root@hcdev yum.repos.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.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 images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 ec7e75e5260c 2 years ago 360MB
registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 2 years ago 360MB
根据镜像创建容器
[root@hcdev yum.repos.d]# docker create -it mysql:5.7
d625d3596ca386e57b047f7e4a50c78ba9330eb094a9ff6afd83a9daa02efd9c
启动MySQL容器
[root@hcdev yum.repos.d]# docker run --name mtmysql -e MYSQL_ROOT_PASSWORD=chengce243 -d -i -p 3306:3306 mysql:5.7
5437d787164bf7174c71a64501151ed2132d030999a37a11c94fba13afcc8a36
[root@hcdev yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5437d787164b 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 -pchengce243
MySQL停止
docker stop mtmysql
也可以
docker stop 5437d787164b
MySQL启动
docker start mtmysql
也可以
docker start 5437d787164b