构建mongo-connector镜像

1.前提

服务器需要安装docker服务

需要能使用外网

使用mongo-connector需要pymongo(连接mongo用到的)docmanager(连接es,solr等用到的).

秉承测试要多次原则,这里测试两次,构建时测试,导入后测试.

2.下载

我这里使用的是python镜像,因为mongo-connector基于python开发

pull镜像

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

镜像重命名(创建tag 删除原有tag)

[root@Ninemax-LPC3 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE

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

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

[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

转载于:https://www.cnblogs.com/erbiaoge/p/7486567.html

你可能感兴趣的:(构建mongo-connector镜像)