1. 程式人生 > >【系列6】使用Dockerfile創建帶mysql5.7的Centos Docker鏡像1

【系列6】使用Dockerfile創建帶mysql5.7的Centos Docker鏡像1

mysql5.7的Centos Dock

1、進入Linux後,使用Docker命令下載MySQL,命令如:

docker pull mysql:5.7

運行該命令後,則會顯示以下日誌:

[root@localhost ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
ad74af05f5a2: Pull complete 
0639788facc8: Pull complete 
de70fa77eb2b: Pull complete 
724179e94999: Pull complete 
50c77fb16ba6: Pull complete 
d51f459239fb: Pull complete 
937bbdd4305a: Pull complete 
35369f9634e1: Pull complete 
f6016aab25f1: Pull complete 
5f1901e920da: Pull complete 
fdf808213c5b: Pull complete 
Digest: sha256:96edf37370df96d2a4ee1715cc5c7820a0ec6286551a927981ed50f0273d9b43Status: Downloaded newer image for mysql:5.7

2、先查看本機都有哪些鏡像,命令如下:

docker images
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 c73c7527c03a        8 days ago          412MB
hello-world         latest              1815c82652c0        7 weeks ago         1.84kB
java                latest              d23bdf5b1b1b        6 months ago        643MB
learn/tutorial      latest              a7876479f1aa        4 years ago         128MB

3.然後啟動我們的mysql的docker容器,命令如下:

docker run --name mysql5.7 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

註意,這裏的容器名字叫:mysql5.7,mysql的root用戶密碼是:123456,映射宿主機子的端口3306到容器的端口3306,倉庫名mysql和標簽(tag)唯一確定了要指定的鏡像,其實如果這裏只有一個mysql也有必要要tag,執行該命令返回的結果是:

9238d9feb10a0c553d950451add144727b659a0972ccf04d7c59c3bfa198ed20

4.查看已經運行的的所有容器,命令如:docker ps

[root@localhost ~]# docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
9238d9feb10a        mysql:5.7           "docker-entrypoint..."   12 seconds ago      Up 9 seconds        0.0.0.0:3306->3306/tcp   mysql5.7
[root@localhost ~]#

5.使用mysql的工具,比如navicat連接成功如下:

技術分享圖片


【系列6】使用Dockerfile創建帶mysql5.7的Centos Docker鏡像1