Docker 安装使用 MongoDB

2017-07-02  本文已影响345人  山哥Samuel

搜索 MongoDB 的镜像

sam@sam-VirtualBox:~$ docker search mongo
NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mongo                          MongoDB document databases provide high av...   3396      [OK]
mongo-express                  Web-based MongoDB admin interface, written...   166       [OK]
mvertes/alpine-mongo           light MongoDB container                         50                   [OK]
mongoclient/mongoclient        Official docker image for Mongoclient, fea...   28                   [OK]
torusware/speedus-mongo        Always updated official MongoDB docker ima...   9                    [OK]
mongooseim/mongooseim-docker   MongooseIM server the latest stable version     9                    [OK]
jacksoncage/mongo              Instant MongoDB sharded cluster                 6                    [OK]
khezen/mongo                   MongoDB Docker image supporting RocksDB st...   4                    [OK]
yeasy/mongo-connector          pipeline from a MongoDB cluster to other s...   4                    [OK]
asteris/apache-php-mongo       Apache2.4 + PHP + Mongo + mod_rewrite           3                    [OK]
ackee/mongo                    MongoDB with fixed Bluemix permissions          1                    [OK]
jessedusty/mongo-flask         Combination of superzazu/flask-python34 an...   1                    [OK]
kobotoolbox/mongo              https://github.com/kobotoolbox/kobo-docker...   1                    [OK]
xemuliam/mongo                 Unofiicial MongoDB docker image on Alpine       1                    [OK]
valtlfelipe/mongo              Docker Image based on the latest Ubuntu im...   1                    [OK]
skandyla/mongo                 Mongodb image based on official mongo 3.4 ...   0                    [OK]
koding/mongo-auto              Koding Mongo image auto build from master ...   0                    [OK]
kobotoolbox/base-mongo         https://github.com/kobotoolbox/kobo-docker...   0                    [OK]
tagplus5/mongo                 mongo                                           0                    [OK]
chpradmin/cp-mongo             mongo                                           0                    [OK]
ekesken/mongo                  docker image for mongo that is configurabl...   0                    [OK]
mapic/mongo                    Dockerfiles for mapic/mongo:latest Docker ...   0                    [OK]
cloudunit/mongo-2-6            /cu-services/images/modules/mongo-2-6           0                    [OK]
bigtruedata/mongo              Image for MongoDB                               0                    [OK]
roadmunk/mongo                 Mongo with replica set configuration and h...   0                    [OK]```

####现在我们安装最新版的 MongoDB

docker pull mongo:3.4.5
下载完后,查看本地的images
sam@sam-VirtualBox:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo 3.4.5 71c101e16e61 9 days ago 358MB


## Start the service, 并且绑定端口到主机的27017端口。这样外边的机器就当你的主机安装了MongoDB一样的访问了。

docker run -p 27017:27017 -v ~/docker/mongo/db:/data/db -d mongo:3.4.5

如果你设置了account,安全起见,加上`--auth`就可以了。

Now you can use your client to connect to it! What?! you dont have? Okay, you can still use this container to use the CUI client. (推荐用 [Robo 3T](https://robomongo.org/download) 来访问。这是一个强大而免费的 MongoDB GUI 管理 Client)

##### Try to get the IP
`docker ps` to get the container id
`docker inspect --format='{{.NetworkSettings.IPAddress}}' $container_id`

##### Run a client to connect it
`docker run -it mongo:3.4.5 mongo --host 172.17.0.2`

### Shutdown

docker exec -i docker ps | grep mongo | sed -r "s/\s+.+//" mongod --shutdown --dbpath /data/db```

上一篇下一篇

猜你喜欢

热点阅读