mirror of
https://github.com/yeasy/docker_practice.git
synced 2024-11-24 23:38:55 +00:00
263 lines
9.3 KiB
Markdown
263 lines
9.3 KiB
Markdown
## [MongoDB](https://hub.docker.com/_/mongo/)
|
|
|
|
### 基本信息
|
|
[MongoDB](https://en.wikipedia.org/wiki/MongoDB) 是开源的 NoSQL 数据库实现。
|
|
|
|
该仓库位于 https://hub.docker.com/_/mongo/,提供了 MongoDB 2.x ~ 3.x 各个版本的镜像。
|
|
|
|
### 使用方法
|
|
默认会在 `27017` 端口启动数据库。
|
|
|
|
```sh
|
|
$ docker run --name some-mongo -d mongo
|
|
```
|
|
|
|
使用其他应用连接到容器,可以用
|
|
|
|
```sh
|
|
$ docker run --name some-app --link some-mongo:mongo -d application-that-uses-mongo
|
|
```
|
|
|
|
或者通过 `mongo`
|
|
|
|
```sh
|
|
$ docker run -it --link some-mongo:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/test"'
|
|
```
|
|
|
|
### Dockerfile
|
|
|
|
#### 2.6 版本
|
|
```
|
|
FROM debian:wheezy
|
|
|
|
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
|
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
|
|
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
ca-certificates wget \
|
|
numactl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# grab gosu for easy step-down from root
|
|
ENV GOSU_VERSION 1.7
|
|
RUN set -x \
|
|
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
|
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
|
&& export GNUPGHOME="$(mktemp -d)" \
|
|
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
|
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
|
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
|
&& chmod +x /usr/local/bin/gosu \
|
|
&& gosu nobody true
|
|
|
|
ENV MONGO_VERSION 2.6.12
|
|
|
|
RUN set -x \
|
|
&& wget -O mongo.tgz "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$MONGO_VERSION.tgz" \
|
|
&& wget -O mongo.tgz.sig "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$MONGO_VERSION.tgz.sig" \
|
|
&& export GNUPGHOME="$(mktemp -d)" \
|
|
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys DFFA3DCF326E302C4787673A01C4E7FAAAB2461C \
|
|
&& gpg --batch --verify mongo.tgz.sig mongo.tgz \
|
|
&& rm -r "$GNUPGHOME" mongo.tgz.sig \
|
|
&& tar -xvf mongo.tgz -C /usr/local --strip-components=1 \
|
|
&& rm mongo.tgz
|
|
|
|
RUN mkdir -p /data/db /data/configdb \
|
|
&& chown -R mongodb:mongodb /data/db /data/configdb
|
|
VOLUME /data/db /data/configdb
|
|
|
|
COPY docker-entrypoint.sh /entrypoint.sh
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
|
EXPOSE 27017
|
|
CMD ["mongod"]
|
|
```
|
|
|
|
#### 3.0 版本
|
|
```
|
|
FROM debian:wheezy
|
|
|
|
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
|
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
|
|
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
numactl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# grab gosu for easy step-down from root
|
|
ENV GOSU_VERSION 1.7
|
|
RUN set -x \
|
|
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
|
|
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
|
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
|
&& export GNUPGHOME="$(mktemp -d)" \
|
|
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
|
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
|
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
|
&& chmod +x /usr/local/bin/gosu \
|
|
&& gosu nobody true \
|
|
&& apt-get purge -y --auto-remove ca-certificates wget
|
|
|
|
# gpg: key 7F0CEB10: public key "Richard Kreuter <richard@10gen.com>" imported
|
|
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 492EAFE8CD016A07919F1D2B9ECBEC467F0CEB10
|
|
|
|
ENV MONGO_MAJOR 3.0
|
|
ENV MONGO_VERSION 3.0.12
|
|
|
|
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list
|
|
|
|
RUN set -x \
|
|
&& apt-get update \
|
|
&& apt-get install -y \
|
|
mongodb-org=$MONGO_VERSION \
|
|
mongodb-org-server=$MONGO_VERSION \
|
|
mongodb-org-shell=$MONGO_VERSION \
|
|
mongodb-org-mongos=$MONGO_VERSION \
|
|
mongodb-org-tools=$MONGO_VERSION \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& rm -rf /var/lib/mongodb \
|
|
&& mv /etc/mongod.conf /etc/mongod.conf.orig
|
|
|
|
RUN mkdir -p /data/db /data/configdb \
|
|
&& chown -R mongodb:mongodb /data/db /data/configdb
|
|
VOLUME /data/db /data/configdb
|
|
|
|
COPY docker-entrypoint.sh /entrypoint.sh
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
|
EXPOSE 27017
|
|
CMD ["mongod"]
|
|
```
|
|
|
|
#### 3.2 版本
|
|
|
|
```
|
|
FROM debian:wheezy
|
|
|
|
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
|
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
|
|
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
numactl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# grab gosu for easy step-down from root
|
|
ENV GOSU_VERSION 1.7
|
|
RUN set -x \
|
|
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
|
|
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
|
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
|
&& export GNUPGHOME="$(mktemp -d)" \
|
|
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
|
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
|
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
|
&& chmod +x /usr/local/bin/gosu \
|
|
&& gosu nobody true \
|
|
&& apt-get purge -y --auto-remove ca-certificates wget
|
|
|
|
# pub 4096R/AAB2461C 2014-02-25 [expires: 2016-02-25]
|
|
# Key fingerprint = DFFA 3DCF 326E 302C 4787 673A 01C4 E7FA AAB2 461C
|
|
# uid MongoDB 2.6 Release Signing Key <packaging@mongodb.com>
|
|
#
|
|
# pub 4096R/EA312927 2015-10-09 [expires: 2017-10-08]
|
|
# Key fingerprint = 42F3 E95A 2C4F 0827 9C49 60AD D68F A50F EA31 2927
|
|
# uid MongoDB 3.2 Release Signing Key <packaging@mongodb.com>
|
|
#
|
|
ENV GPG_KEYS \
|
|
DFFA3DCF326E302C4787673A01C4E7FAAAB2461C \
|
|
42F3E95A2C4F08279C4960ADD68FA50FEA312927
|
|
RUN set -ex \
|
|
&& for key in $GPG_KEYS; do \
|
|
apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
|
|
done
|
|
|
|
ENV MONGO_MAJOR 3.2
|
|
ENV MONGO_VERSION 3.2.8
|
|
|
|
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list
|
|
|
|
RUN set -x \
|
|
&& apt-get update \
|
|
&& apt-get install -y \
|
|
mongodb-org=$MONGO_VERSION \
|
|
mongodb-org-server=$MONGO_VERSION \
|
|
mongodb-org-shell=$MONGO_VERSION \
|
|
mongodb-org-mongos=$MONGO_VERSION \
|
|
mongodb-org-tools=$MONGO_VERSION \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& rm -rf /var/lib/mongodb \
|
|
&& mv /etc/mongod.conf /etc/mongod.conf.orig
|
|
|
|
RUN mkdir -p /data/db /data/configdb \
|
|
&& chown -R mongodb:mongodb /data/db /data/configdb
|
|
VOLUME /data/db /data/configdb
|
|
|
|
COPY docker-entrypoint.sh /entrypoint.sh
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
|
EXPOSE 27017
|
|
CMD ["mongod"]
|
|
```
|
|
|
|
#### 3.3 版本
|
|
|
|
```
|
|
FROM debian:jessie
|
|
|
|
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
|
|
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb
|
|
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends \
|
|
numactl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# grab gosu for easy step-down from root
|
|
ENV GOSU_VERSION 1.7
|
|
RUN set -x \
|
|
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
|
|
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
|
|
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
|
|
&& export GNUPGHOME="$(mktemp -d)" \
|
|
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
|
|
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
|
|
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
|
|
&& chmod +x /usr/local/bin/gosu \
|
|
&& gosu nobody true \
|
|
&& apt-get purge -y --auto-remove ca-certificates wget
|
|
|
|
# pub 4096R/A15703C6 2016-01-11 [expires: 2018-01-10]
|
|
# Key fingerprint = 0C49 F373 0359 A145 1858 5931 BC71 1F9B A157 03C6
|
|
# uid MongoDB 3.4 Release Signing Key <packaging@mongodb.com>
|
|
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 0C49F3730359A14518585931BC711F9BA15703C6
|
|
|
|
ENV MONGO_MAJOR 3.3
|
|
ENV MONGO_VERSION 3.3.10
|
|
|
|
RUN echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list
|
|
|
|
RUN set -x \
|
|
&& apt-get update \
|
|
&& apt-get install -y \
|
|
mongodb-org-unstable=$MONGO_VERSION \
|
|
mongodb-org-unstable-server=$MONGO_VERSION \
|
|
mongodb-org-unstable-shell=$MONGO_VERSION \
|
|
mongodb-org-unstable-mongos=$MONGO_VERSION \
|
|
mongodb-org-unstable-tools=$MONGO_VERSION \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& rm -rf /var/lib/mongodb \
|
|
&& mv /etc/mongod.conf /etc/mongod.conf.orig
|
|
|
|
RUN mkdir -p /data/db /data/configdb \
|
|
&& chown -R mongodb:mongodb /data/db /data/configdb
|
|
VOLUME /data/db /data/configdb
|
|
|
|
COPY docker-entrypoint.sh /entrypoint.sh
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
|
|
|
EXPOSE 27017
|
|
CMD ["mongod"]
|
|
``` |