構建mongo-connector鏡像

1.前提

服務器須要安裝docker服務 python

須要能使用外網 linux

使用mongo-connector須要pymongo(鏈接mongo用到的)docmanager(鏈接es,solr等用到的). docker

秉承測試要屢次原則,這裏測試兩次,構建時測試,導入後測試. vim

2.下載

我這裏使用的是python鏡像,由於mongo-connector基於python開發 bash

pull鏡像

[root@Ninemax-LPC3 ~]# docker pull daocloud.io/library/python:3.4.6-jessie服務器

鏡像重命名(建立tag 刪除原有tag)

[root@Ninemax-LPC3 ~]# docker images elasticsearch

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 測試

daocloud.io/library/python 3.4.6-jessie c323ccfafc9b 6 weeks ago 679.5 MB this

[root@Ninemax-LPC3 ~]# docker tag daocloud.io/library/python:3.4.6-jessie python:3.4.6 url

[root@Ninemax-LPC3 ~]# docker rmi daocloud.io/library/python:3.4.6-jessie

Untagged: daocloud.io/library/python:3.4.6-jessie

[root@Ninemax-LPC3 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

python 3.4.6 c323ccfafc9b 6 weeks ago 679.5 MB

3.安裝mongo-connector

建立容器

[root@Ninemax-LPC3 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

python 3.4.6 c323ccfafc9b 6 weeks ago 679.5 MB

[root@Ninemax-LPC3 ~]# docker run --name mongo-connector -ti python:3.4.6 bash

安裝vim(此處可略過,看你心情!)

鑑於國內下載國外插件速度太TM慢了,先按這個,在開一個窗口鏈接去安裝剩下的軟件

root@fa9aaee571a8:/etc/apt# apt-get install vim

若是報錯更新一下源索引:

root@fa9aaee571a8:/etc/apt# apt-get update

更新後,再次嘗試安裝

root@fa9aaee571a8:/etc/apt# apt-get install vim

安裝pymongo

root@fa9aaee571a8:/# pip install pymongo

Collecting pymongo

Downloading pymongo-3.5.1-cp34-cp34m-manylinux1_x86_64.whl (366kB)

100% |████████████████████████████████| 368kB 26kB/s

Installing collected packages: pymongo

Successfully installed pymongo-3.5.1

   

安裝docmanager

root@fa9aaee571a8:/# pip install 'elastic2-doc-manager[elastic5]'

其餘docmanager命令:

Target System

Install Command

MongoDB

pip install mongo-connector

Elasticsearch 1.x

pip install 'mongo-connector[elastic]'

Amazon Elasticsearch 1.x Service

pip install 'mongo-connector[elastic-aws]'

Elasticsearch 2.x

pip install 'mongo-connector[elastic2]'

Amazon Elasticsearch 2.x Service

pip install 'mongo-connector[elastic2-aws]'

Elasticsearch 5.x

pip install 'mongo-connector[elastic5]'

Solr

pip install 'mongo-connector[solr]'

安裝mongo-connector

安裝mongo-connector

root@fa9aaee571a8:/# pip install mongo-connector

查看安裝文件

root@fa9aaee571a8:/# pip list

DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.

elastic2-doc-manager (0.3.0)

elasticsearch (5.4.0)

mongo-connector (2.5.1)

pip (9.0.1)

pymongo (3.5.1)

setuptools (36.2.2)

urllib3 (1.22)

wheel (0.29.0)

測試mongo-connector

root@fa9aaee571a8:/# mongo-connector -m 10.12.20.9:27017 -t 10.12.20.3:9201 -d elastic2_doc_manager -n nstlStorage.SOURCE_V01

Logging to /mongo-connector.log.

導出容器

root@fa9aaee571a8:/# exit

[root@Ninemax-LPC3 ~]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

fa9aaee571a8 python:3.4.6 "bash" 2 hours ago Up 4 minutes mongo-connector

[root@Ninemax-LPC3 ~]# docker stop -t 0 fa9aaee571a8

fa9aaee571a8

[root@Ninemax-LPC3 ~]# docker export fa9aaee571a8 > ./mongo-connector.tar

[root@Ninemax-LPC3 ~]# ls |grep mongo-connector.tar

mongo-connector.tar

4.測試

導入鏡像

[root@Ninemax-LPC3 ~]# docker import - mongo-cennector:2.0 < mongo-connector.tar

c1a26db626be25d8321b2d5d0715dae4c419048252aa6baa757f70b0c32eacc6

[root@Ninemax-LPC3 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

mongo-cennector 2.0 c1a26db626be About a minute ago 719 MB

python 3.4.6 c323ccfafc9b 6 weeks ago 679.5 MB

建立容器

[root@Ninemax-LPC3 ~]# docker run -t -i --name mongo-cennector2 --net=host mongo-cennector:2.0 bash

root@Ninemax-LPC3:/#

測試

root@fa9aaee571a8:/# mongo-connector -m 10.12.20.9:27017 -t 10.12.20.3:9201 -d elastic2_doc_manager -n nstlStorage.SOURCE_V01

Logging to /mongo-connector.log.

5.最後

這鏡像賊雞兒大,腦闊痛 (TvT)…… 哪天用dockefile構建個小的吧

鏡像共享出來:docker pull registry.cn-qingdao.aliyuncs.com/ninemax/mongo-connector:python-1.0

相關文章
相關標籤/搜索