Mac上使用Docker如何快速啟動(dòng)MySQL測(cè)試
本文主要討論使用Docker快速啟動(dòng) MySQL 測(cè)試的方法,包括Mac環(huán)境。一起看看吧!
近來(lái)業(yè)界有很多對(duì)Docker的討論,其生態(tài)系統(tǒng)發(fā)展得很快,然而,從簡(jiǎn)單的“入門”或“引導(dǎo)”類的文章中能容易地找到成熟的技術(shù),但Docker不然。我在Mac上試玩過(guò)Docker,但Mac絕對(duì)是Docker界的二等公民。當(dāng)我在Giuseppe的博客上看到關(guān)于在Mac上使用新Docker beta《Docker for Mac beta and MySQL》一文時(shí),決定自己來(lái)嘗試下。這些步驟適用于Mac(Windows也可能),亦能適配Linux環(huán)境(GA版本,Docker 1.11.1)。
首先,在Mac上注冊(cè)新的Docker測(cè)試版程序,接著從Docker中獲得下載代碼。此過(guò)程我耗時(shí)一天,但應(yīng)該不久就會(huì)發(fā)布完整版。安裝完成后,我需要為常見(jiàn)的MySQL版本設(shè)置一些Docker容器,沙箱也就有了。方法如下:
jayj@~ [510]$ docker network create test 90005b3ffa9fef1f817ee4965e794a567404c9a8d5bf07320514e7d848d59ff9 jayj@~ [511]$ docker run --name=mysql57 --net=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql/mysql-server:5.7 6c80fa89610dbd5418ba474ad7d5451cd061f80a8a72ff2e718341827a08144b jayj@~ [512]$ docker run -it --rm --net=test -e MYSQL_HOST=mysql57 mysql/shell init Creating a Classic Session to root@mysql57:3306 Enter password: No default schema selected. enableXProtocol: Installing plugin mysqlx... enableXProtocol: done
一些經(jīng)驗(yàn)總結(jié):
我為我的容器創(chuàng)建了一個(gè)名為“測(cè)試”的網(wǎng)絡(luò)以共享,本質(zhì)是容器之間一個(gè)專用的私有網(wǎng)絡(luò)。我喜歡這個(gè)是因?yàn)樵谙嚓P(guān)的端口是監(jiān)聽多個(gè)容器,也不必設(shè)置主機(jī)操作系統(tǒng)的端口。
我將Oracle的官方MySQL Docker容器啟動(dòng)一個(gè)MySQL 5.7的鏡像,在綁定到該測(cè)試網(wǎng)絡(luò)。
我使用了MySQL /shell鏡像(來(lái)自O(shè)racle)來(lái)初始化MySQL 5.7服務(wù)器上的mysqlx插件。需要注意的是,我并沒(méi)有輸入密碼,因?yàn)槲覜](méi)有創(chuàng)建一個(gè)服務(wù)器(不安全,但它是一個(gè)沙箱)。
這個(gè)里面的Shell使用了運(yùn)行后刪除的臨時(shí)容器,所以并不會(huì)破壞Docker ps-a輸出。
所以,現(xiàn)在我希望能夠使用標(biāo)準(zhǔn)的MySQL命令行或新的MySQL shell來(lái)訪問(wèn)這個(gè)容器。讓它看起來(lái)很干凈,因此我添加了一些bash別名:
alias mysqlsh='docker run -it --rm --net=test mysql/shell' alias mysql='docker run -it --rm -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --net=test --entrypoint="mysql" mysql/mysql-server:5.7'
這些以后,我可以直接調(diào)用他們并通過(guò)正常的命令行選項(xiàng)來(lái)連接我的MySQL 5.7鏡像,就像使用的是一個(gè)原生的MySQL CLI binary。從MySQL 5.7鏡像中使用MySQL CLI:
jayj@~ [524]$ mysql -h mysql57 Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 4 Server version: 5.7.12 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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> show schemas; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec)
使用MySQL shell:
jayj@~ [527]$ mysqlsh -h mysql57 -u root --session-type=node Creating a Node Session to root@mysql57:33060 Enter password: No default schema selected. Welcome to MySQL Shell 1.0.3 Development Preview Copyright (c) 2016, 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', 'h' or '?' for help. Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries. mysql-js> sql Switching to SQL mode... Commands end with ; mysql-sql> show schemas; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql-sql>
現(xiàn)在,如果為了一些事情想要運(yùn)行檢查MySQL 5.5,可以這樣做:
jayj@~ [530]$ docker run --name=mysql55 --net=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql/mysql-server:5.5 Unable to find image 'mysql/mysql-server:5.5' locally 5.5: Pulling from mysql/mysql-server a3ed95caeb02: Already exists ffe36b360c6d: Already exists 646f220a8b5d: Pull complete ed65e4fea7ed: Pull complete d34b408b18dd: Pull complete Digest: sha256:12f0b7025d1dc0e7b40fc6c2172106cdf73b8832f2f910ad36d65228d9e4c433 Status: Downloaded newer image for mysql/mysql-server:5.5 6691dd9d42c73f53baf2968bcca92b7f4d26f54bb01d967be475193305affd4f jayj@~ [531]$ mysql -h mysql55 Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1 Server version: 5.5.49 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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> show schemas; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) 或者,Percona Server: jayj@~ [534]$ docker run --name=ps57 --net=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d percona/percona-server:5.7 Unable to find image 'percona/percona-server:5.7' locally 5.7: Pulling from percona/percona-server a3ed95caeb02: Pull complete a07226856d92: Pull complete eee62d87a612: Pull complete 4c6755120a98: Pull complete 10eab0da5972: Pull complete d5159a6502a4: Pull complete e595a1a01d00: Pull complete Digest: sha256:d57f0ce736f5403b1714ff8d1d6b91d5a7ee7271f30222c2bc2c5cad4b4e6950 Status: Downloaded newer image for percona/percona-server:5.7 9db503852747bc1603ab59455124663e8cedf708ac6d992cff9b43e2fbebd167 jayj@~ [537]$ mysql -h ps57 Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 Server version: 5.7.10-3 Percona Server (GPL), Release 3, Revision 63dafaf Copyright (c) 2000, 2016, 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>
所以,這一切都很好,一旦鏡像被本地緩存,上下調(diào)整新的容器可以實(shí)現(xiàn)無(wú)痛和快速。所有這一切的工作都是與我的操作系統(tǒng)工作站分離的??赡苓€有其他事情可以使用這種設(shè)置,但還沒(méi)找到方法(如加載數(shù)據(jù)文件、運(yùn)行代碼來(lái)連接這些容器等),但將來(lái)我會(huì)解決。
以上所述是小編給大家介紹的Mac上使用Docker快速啟動(dòng)MySQL測(cè)試的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Docker啟動(dòng)mysql服務(wù)的實(shí)現(xiàn)步驟
- Docker啟動(dòng)mysql配置實(shí)現(xiàn)過(guò)程
- 如何讓docker中的mysql啟動(dòng)時(shí)自動(dòng)執(zhí)行sql語(yǔ)句
- docker mysql啟動(dòng)時(shí)執(zhí)行初始化sql
- docker中mysql初始化及啟動(dòng)失敗問(wèn)題解決方案
- Docker容器啟動(dòng)時(shí)初始化Mysql數(shù)據(jù)庫(kù)的方法
- docker啟動(dòng)mysql及-e MYSQL_ROOT_PASSWORD=my-secret-pw問(wèn)題解決
相關(guān)文章
淺談docker運(yùn)行nginx為什么要使用daemon off
這篇文章主要介紹了淺談docker運(yùn)行nginx為什么要使用daemon off,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-01-01
詳解使用Docker快速部署ELK環(huán)境(最新5.5.1版本)
這篇文章主要介紹了詳解使用Docker快速部署ELK環(huán)境(最新5.5.1版本),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
Docker跨平臺(tái)和環(huán)境部署的過(guò)程詳解
Docker是一個(gè)開放源代碼的容器化平臺(tái),它能夠?qū)崿F(xiàn)應(yīng)用及其依賴的打包,從而實(shí)現(xiàn)跨平臺(tái)和環(huán)境的快速部署,本文介紹了Docker的基本概念、優(yōu)勢(shì)和基本使用方法,包括安裝、啟動(dòng)、構(gòu)建鏡像和部署應(yīng)用等步驟2024-11-11
Docker容器如何訪問(wèn)宿主機(jī)的Mysql數(shù)據(jù)庫(kù)
使用Docker能實(shí)現(xiàn)服務(wù)的容器化,并使用容器間網(wǎng)絡(luò)在它們之間進(jìn)行通信,下面這篇文章主要給大家介紹了關(guān)于Docker容器如何訪問(wèn)宿主機(jī)的Mysql數(shù)據(jù)庫(kù),需要的朋友可以參考下2024-04-04
Docker Desktop更改鏡像存儲(chǔ)位置的實(shí)現(xiàn)
本文主要主要介紹了Docker Desktop更改鏡像存儲(chǔ)位置的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
docker-maven-plugin 插件無(wú)法拉取對(duì)應(yīng)jar包問(wèn)題
這篇文章主要介紹了docker-maven-plugin 插件無(wú)法拉取問(wèn)題,總是報(bào)錯(cuò),如何解決這個(gè)問(wèn)題呢,下面小編給大家?guī)?lái)了解決方法,一起看看吧2021-09-09
Docker中搭建配置Git環(huán)境的過(guò)程
工作中遇到了需要在Docker環(huán)境中操作GitLab倉(cāng)庫(kù)的場(chǎng)景,需要事先在Docker中搭好Git環(huán)境,但是很多朋友不是很清楚Docker配置Git環(huán)境的過(guò)程,今天通過(guò)本文給大家詳細(xì)介紹下,需要的朋友參考下吧2021-08-08
Docker初級(jí)網(wǎng)絡(luò)端口映射的配置
這篇文章主要介紹了Docker初級(jí)網(wǎng)絡(luò)端口映射的配置,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
docker?gitea?drone實(shí)現(xiàn)超輕量級(jí)CI?CD實(shí)戰(zhàn)詳解
這篇文章主要為大家介紹了docker?gitea?drone實(shí)現(xiàn)超輕量級(jí)CI?CD實(shí)戰(zhàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10

