Docker 基础教程

Docker 安装

Docker 使用

Docker 实例

Docker 参考手册

original icon
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.knowledgedict.com/tutorial/docker-install-mongodb.html

Docker 安装 MongoDB


Docker 安装 MongoDB 主要有 2 种方法,分别是直接通过 docker 命令安装或通过 Dockerfile 构建。MongoDB 相关的 docker 镜像所有版本可以查看镜像库的 MongoDB tags,官方地址为 https://hub.docker.com/_/mongo?tab=tags

方式一:docker pull mongo

关键字搜索相关镜像

首先通过 mongo 关键字查询当前镜像库的所有 mongo 相关的镜像,使用 docker search 命令,具体示例如下:

knowledgedict@Mac ~ $ docker search mongo
NAME                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mongo                               MongoDB document databases provide high av...   7081      [OK]       
mongo-express                       Web-based MongoDB admin interface, written...   744       [OK]       
tutum/mongodb                       MongoDB Docker image – listens in port 270...   229                  [OK]
bitnami/mongodb                     Bitnami MongoDB Docker Image                    124                  [OK]
mongoclient/mongoclient             Official docker image for Mongoclient, fea...   86                   [OK]
mongooseim/mongooseim               Small docker image for MongooseIM - robust...   19                   
frodenas/mongodb                    A Docker Image for MongoDB                      18                   [OK]
cvallance/mongo-k8s-sidecar         Kubernetes side car to setup and maintain ...   16                   [OK]
arm64v8/mongo                       MongoDB document databases provide high av...   9                    
centos/mongodb-32-centos7           MongoDB NoSQL database server                   8                    
circleci/mongo                      CircleCI images for MongoDB                     8                    [OK]
webhippie/mongodb                   Docker images for MongoDB                       7                    [OK]
istepanov/mongodump                 Docker image with mongodump running as a c...   6                    [OK]
centos/mongodb-36-centos7           MongoDB NoSQL database server                   5                    
centos/mongodb-26-centos7           MongoDB NoSQL database server                   5                    
neowaylabs/mongodb-mms-agent        This Docker image with MongoDB Monitoring ...   4                    [OK]
eses/mongodb_exporter               mongodb exporter for prometheus                 4                    [OK]
requilence/mongodb-backup           mongo backup container                          4                    [OK]
centos/mongodb-34-centos7           MongoDB NoSQL database server                   3                    
andreasleicher/mongo-azure-backup   a docker container to backup a mongodb usi...   2                    [OK]
openshift/mongodb-24-centos7        DEPRECATED: A Centos7 based MongoDB v2.4 i...   1                    
ansibleplaybookbundle/mongodb-apb   An APB to deploy MongoDB.                       1                    [OK]
ekesken/mongo                       docker image for mongo that is configurabl...   1                    [OK]
phenompeople/mongodb                 MongoDB is an open-source, document datab...   0                    [OK]
martel/mongo-replica-ctrl           A dockerized controller for a Mongo db rep...   0                    [OK]

拉取指定版本的镜像

从镜像库拉取镜像用 docker pull 命令。

knowledgedict@Mac ~ $ docker pull mongo:4.4.0
4.4.0: Pulling from library/mongo
7595c8c21622: Pull complete 
d13af8ca898f: Pull complete 
70799171ddba: Pull complete 
b6c12202c5ef: Pull complete 
f8718c532d71: Pull complete 
9035443a91bc: Pull complete 
93ca553166d9: Pull complete 
bc866a5c284c: Pull complete 
6faca936e7b3: Pull complete 
1dc2a767b81f: Pull complete 
56dee77e3145: Pull complete 
b967fd908de0: Pull complete 
7cd9ac470a46: Pull complete 
Digest: sha256:f8c327278bd1a37a5900b2e1ac529221ade80eb54e818e0c3bf04804094c7729
Status: Downloaded newer image for mongo:4.4.0

下载完成后,可以在本地的镜像列表查看相关信息,如下:

knowledgedict@Mac ~ $ docker images mongo
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mongo               4.4.0               aa22d67221a0        8 days ago          493 MB

运行容器

运行容器使用 docker run 命令,具体如下:

knowledgedict@Mac ~ $ docker run -itd --name mongo-demo -p 27017:27017 mongo:4.4.0
392ccb4d83e7a0406f56261286f03b1c626cc588ab16625cfd4b6ee513675364

启动后,查看相应容器运行信息:

knowledgedict@Mac ~ $ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
392ccb4d83e7        mongo:4.4.0         "docker-entrypoint..."   40 minutes ago      Up 22 seconds       0.0.0.0:27017->27017/tcp   mongo-demo

 

Docker 安装 Redis 主要有 2 种方法,分别是直接通过 docker 命令安装或通过 Dockerfile 构建。redis 相 ...
Docker 安装 Nginx 主要有 2 种方法,分别是直接通过 docker 命令安装或通过 Dockerfile 构建。nginx 相 ...
Docker 安装 php 主要有 2 种方法,分别是直接通过 docker 命令安装或通过 Dockerfile 构建。php 相关的 d ...
MongoDB 主要分为社区版(Community)和企业版(Enterprise),其中社区版本是免费的,官方提供了 Windows、Li ...
Django是一个流行的PythonWeb框架,Docker是一个用于容器化应用程序的平台。txt的文件,列出项目的依赖:构建Docker镜 ...