Docker安裝Mysql服務

Docker安裝Mysql服務:

1.檢索mysql鏡像

檢索鏡像命令:docker search mysql

2.拉取mysql鏡像

拉取鏡像命令:docker pull mysql

獲取固定版本鏡像:docker pull mysql:5.6

localhost:~ zhangjiankang$ docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
6ae821421a7d: Pull complete
a9e976e3aa6d: Pull complete
e3735e44a020: Pull complete
bfd564e9483f: Pull complete
df705f26e488: Pull complete
0c5547f73d62: Pull complete
f437382cf8a1: Pull complete
b8e2d50f1513: Pull complete
e2e3c9928180: Pull complete
b60db6d282cd: Pull complete
1d32deab69c6: Pull complete
408a40cd2e9c: Pull complete
Digest: sha256:a571337738c9205427c80748e165eca88edc5a1157f8b8d545fa127fc3e29269
Status: Downloaded newer image for mysql:latest

3.查詢mysql鏡像

查詢鏡像命令:docker images

刪除鏡像命令:docker rmi <image id>

4.用docker啓動mysql容器

啓動命令:docker run --name mysql5.6 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

命令解析:
--name:容器名

--p:映射宿主主機端口

-v:掛載宿主目錄到容器目錄

-e:設置環境變量,此處指定root密碼

-d:後臺運行容器

mysql:5.6 爲鏡像名稱和tag版本,如果是最新版本後綴可忽略

localhost:~ zhangjiankang$ docker run --name mysql5.6 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
200c73419302c7f032629449965ce4a2f73e12f1e1c9de920aa9193d3fa3fed3
localhost:~ zhangjiankang$ docker ps

5.安裝成功

6.進入mysql容器

進入容器命令:docker exec -it mysql bash

登錄MySQL命令:mysql -u root -p

localhost:~ zhangjiankang$ docker exec -it mysql5.6 bash
root@200c73419302:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.43 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.
mysql>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章