基于Docker的數(shù)據(jù)庫開發(fā)環(huán)境
前文介紹了sqlite/mysql/mssql等數(shù)據(jù)庫系統(tǒng)在ubuntu的安裝與部署過程,相對是比較復(fù)雜的,需要耐心等待下載以及排除各種故障,對于開發(fā)人員來說是不太友好。在某些情況下,開發(fā)人員要測試在多個數(shù)據(jù)庫環(huán)境下軟件的正確性,需要部署多個數(shù)據(jù)庫,為此可以使用Docker技術(shù)。
Docker提供了基于鏡像的運(yùn)行環(huán)境,可以將操作系統(tǒng)、應(yīng)用程序以及相關(guān)依賴打包,為使用者提供完整的使用體驗,因此一經(jīng)推出大獲好評,迅速成為主流的軟件開發(fā)技術(shù)之一。Docker有著完善的命令行功能,在Windows環(huán)境下有多種GUI管理軟件,本文對Docker不再贅述。下面先在ubuntu bionic上建立Docker服務(wù),隨后基于Docker composer將多個數(shù)據(jù)庫打包啟動,為開發(fā)者提供多數(shù)據(jù)庫支持環(huán)境。
# 刪除舊版本 sudo apt-get remove docker docker-engine docker.io containerd runc sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common # 真正有用的部分 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # aliyun mirrors curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update sudo apt-get install -y docker-ce sudo systemctl enable docker sudo systemctl start docker sudo usermod -aG docker $USER sudo systemctl daemon-reload sudo systemctl restart docker # 不在此機(jī)上開發(fā)python可以直接安裝這個基于python2.7.17的低版本應(yīng)用 apt install docker-compose
使用scp或者直接vi編輯Docker-compse.yml文件如下:
version: "3.3" services: clickhouseserver: restart: always image: yandex/clickhouse-server:21.6.5.37-alpine container_name: clickhouseserver hostname: clickhouseserver environment: - TZ=Asia/Shanghai ports: - 8123:8123 - 9000:9000 ulimits: nofile: soft: 262144 hard: 262144 sqlserver: image: mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04 restart: always container_name: mssql environment: - ACCEPT_EULA=Y - SA_PASSWORD=Zm88488848 ports: - 1433:1433 mysql: image: mysql command: --default-authentication-plugin=mysql_native_password restart: always ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: 88488848 pg: image: postgres restart: always ports: - 5432:5432 environment: POSTGRES_PASSWORD: 88488848
隨后運(yùn)行以下命令啟動。文章來源:http://www.zghlxwxcb.cn/news/detail-492160.html
# 啟動編排,可以按ctrl-c中止 docker-compose up # 類似于服務(wù)的永久啟動。 docker-compose up -d
在第一次啟動時,由于本地沒有對應(yīng)的鏡像,會自動下載,時間稍長些。后續(xù)啟動時將非??焖?。由于以上數(shù)據(jù)庫不真正投入生產(chǎn)環(huán)境,所以沒有引入掛載點(diǎn)。此外,根據(jù)官方文檔要求,sqlserver鏡像在配置時,必須使用強(qiáng)口令(8位大小寫字母與符號的混合)。另,8848的意思是珠峰的高度。文章來源地址http://www.zghlxwxcb.cn/news/detail-492160.html
到了這里,關(guān)于Python工具箱系列(三十六)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!