From 9723e9c01e127960750fc0a88868ec21132a6eeb Mon Sep 17 00:00:00 2001 From: KennyLee Date: Tue, 23 May 2017 14:34:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eredis=E7=9A=84=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...-03-29-docker-quicktip-4-remote-volumes.md | 2 +- nfs/README.md | 29 ++++++++ nfs/docker-compose.yml | 16 +++++ redis/README.md | 3 + redis/image-build/3.2/Dockerfile | 71 +++++++++++++++++++ redis/image-build/3.2/alpine/Dockerfile | 55 ++++++++++++++ .../3.2/alpine/docker-entrypoint.sh | 16 +++++ redis/image-build/3.2/docker-entrypoint.sh | 16 +++++ 8 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 nfs/docker-compose.yml create mode 100644 redis/README.md create mode 100644 redis/image-build/3.2/Dockerfile create mode 100644 redis/image-build/3.2/alpine/Dockerfile create mode 100644 redis/image-build/3.2/alpine/docker-entrypoint.sh create mode 100644 redis/image-build/3.2/docker-entrypoint.sh diff --git a/nfs/2014-03-29-docker-quicktip-4-remote-volumes.md b/nfs/2014-03-29-docker-quicktip-4-remote-volumes.md index 442df00..929d7e2 100644 --- a/nfs/2014-03-29-docker-quicktip-4-remote-volumes.md +++ b/nfs/2014-03-29-docker-quicktip-4-remote-volumes.md @@ -47,7 +47,7 @@ When you combine this with using volumes-from things begin to get a bit more pow # NFS Server docker run -d -v /tmp ubuntu --name foo bash -c "echo foo > /tmp/foo" docker run -d --name nfs-server --privileged --volumes-from foo cpuguy83/nfs-server /tmp -docker inspect --format '{{ .NetworkSettings.IPAddress }}' nfs-server +docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nfs-server 10.0.1.100 ``` diff --git a/nfs/README.md b/nfs/README.md index b24aa2b..2a7d6cd 100755 --- a/nfs/README.md +++ b/nfs/README.md @@ -3,9 +3,38 @@ Docker NFS Server fork for [cpuguy83/docker-nfs-server](https://github.com/cpuguy83/docker-nfs-server) +Test +--- +```bash +# 启动 nfs-server +docker-compose up -d +# 查看nfs-server的ip +docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nfs-server +# 创建,并且进入centos容器,连接nfs_default网络 +docker run -it --network="nfs_nfs" --privileged --rm registry.cn-hangzhou.aliyuncs.com/kennylee/centos:7 bash +yum makecache && yum install -y showmount nfs-utils +rpcbind start +showmount -e 172.20.0.2 +``` + +正常的话,会看到下面信息 + +>[root@d9febac7e894 ~]# showmount -e 172.24.0.2 +>Export list for 172.24.0.2: +>/tmp * + +``` +# 挂载 +mkdir -p /usr/local/test +mount -t nfs4 172.20.0.2:/tmp/ /usr/local/test +``` + Usage ---- ```bash +docker run -d --name nfs --privileged cpuguy83/nfs-server /path/to/share /path/to/share2 /path/to/shareN + + docker run -d --name nfs --privileged cpuguy83/nfs-server /path/to/share /path/to/share2 /path/to/shareN ``` diff --git a/nfs/docker-compose.yml b/nfs/docker-compose.yml new file mode 100644 index 0000000..506a2ce --- /dev/null +++ b/nfs/docker-compose.yml @@ -0,0 +1,16 @@ +version: '2' + +networks: + &network nfs: + driver: bridge + +services: + nfs-server: + image: registry.cn-hangzhou.aliyuncs.com/kennylee/nfs + container_name: "nfs-server" + volumes: + - /tmp/:/tmp/ + privileged: true + command: /tmp/ + networks: + - *network diff --git a/redis/README.md b/redis/README.md new file mode 100644 index 0000000..d83c32c --- /dev/null +++ b/redis/README.md @@ -0,0 +1,3 @@ +fork for https://github.com/docker-library/redis + + diff --git a/redis/image-build/3.2/Dockerfile b/redis/image-build/3.2/Dockerfile new file mode 100644 index 0000000..6c5445c --- /dev/null +++ b/redis/image-build/3.2/Dockerfile @@ -0,0 +1,71 @@ +FROM registry.cn-hangzhou.aliyuncs.com/kennylee/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 redis && useradd -r -g redis redis + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + wget \ + && 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 REDIS_VERSION 3.2.9 +ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-3.2.9.tar.gz +ENV REDIS_DOWNLOAD_SHA 6eaacfa983b287e440d0839ead20c2231749d5d6b78bbe0e0ffa3a890c59ff26 + +# for redis-sentinel see: http://redis.io/topics/sentinel +RUN set -ex \ + \ + && buildDeps=' \ + gcc \ + libc6-dev \ + make \ + ' \ + && apt-get update \ + && apt-get install -y $buildDeps --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* \ + \ + && wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL" \ + && echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c - \ + && mkdir -p /usr/src/redis \ + && tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \ + && rm redis.tar.gz \ + \ +# Disable Redis protected mode [1] as it is unnecessary in context +# of Docker. Ports are not automatically exposed when running inside +# Docker, but rather explicitely by specifying -p / -P. +# [1] https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da + && grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 1$' /usr/src/redis/src/server.h \ + && sed -ri 's!^(#define CONFIG_DEFAULT_PROTECTED_MODE) 1$!\1 0!' /usr/src/redis/src/server.h \ + && grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 0$' /usr/src/redis/src/server.h \ +# for future reference, we modify this directly in the source instead of just supplying a default configuration flag because apparently "if you specify any argument to redis-server, [it assumes] you are going to specify everything" +# see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840 +# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default) + \ + && make -C /usr/src/redis \ + && make -C /usr/src/redis install \ + \ + && rm -r /usr/src/redis \ + \ + && apt-get purge -y --auto-remove $buildDeps + +RUN mkdir /data && chown redis:redis /data +VOLUME /data +WORKDIR /data + +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["docker-entrypoint.sh"] + +EXPOSE 6379 +CMD [ "redis-server" ] diff --git a/redis/image-build/3.2/alpine/Dockerfile b/redis/image-build/3.2/alpine/Dockerfile new file mode 100644 index 0000000..ebc6055 --- /dev/null +++ b/redis/image-build/3.2/alpine/Dockerfile @@ -0,0 +1,55 @@ +FROM registry.cn-hangzhou.aliyuncs.com/kennylee/alpine:3.4 + +# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added +RUN addgroup -S redis && adduser -S -G redis redis + +# grab su-exec for easy step-down from root +RUN apk add --no-cache 'su-exec>=0.2' + +ENV REDIS_VERSION 3.2.9 +ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-3.2.9.tar.gz +ENV REDIS_DOWNLOAD_SHA 6eaacfa983b287e440d0839ead20c2231749d5d6b78bbe0e0ffa3a890c59ff26 + +# for redis-sentinel see: http://redis.io/topics/sentinel +RUN set -ex \ + \ + && apk add --no-cache --virtual .build-deps \ + gcc \ + linux-headers \ + make \ + musl-dev \ + tar \ + \ + && wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL" \ + && echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c - \ + && mkdir -p /usr/src/redis \ + && tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \ + && rm redis.tar.gz \ + \ +# Disable Redis protected mode [1] as it is unnecessary in context +# of Docker. Ports are not automatically exposed when running inside +# Docker, but rather explicitely by specifying -p / -P. +# [1] https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da + && grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 1$' /usr/src/redis/src/server.h \ + && sed -ri 's!^(#define CONFIG_DEFAULT_PROTECTED_MODE) 1$!\1 0!' /usr/src/redis/src/server.h \ + && grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 0$' /usr/src/redis/src/server.h \ +# for future reference, we modify this directly in the source instead of just supplying a default configuration flag because apparently "if you specify any argument to redis-server, [it assumes] you are going to specify everything" +# see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840 +# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default) + \ + && make -C /usr/src/redis \ + && make -C /usr/src/redis install \ + \ + && rm -r /usr/src/redis \ + \ + && apk del .build-deps + +RUN mkdir /data && chown redis:redis /data +VOLUME /data +WORKDIR /data + +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["docker-entrypoint.sh"] + +EXPOSE 6379 +CMD [ "redis-server" ] diff --git a/redis/image-build/3.2/alpine/docker-entrypoint.sh b/redis/image-build/3.2/alpine/docker-entrypoint.sh new file mode 100644 index 0000000..527b232 --- /dev/null +++ b/redis/image-build/3.2/alpine/docker-entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +# first arg is `-f` or `--some-option` +# or first arg is `something.conf` +if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then + set -- redis-server "$@" +fi + +# allow the container to be started with `--user` +if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then + chown -R redis . + exec su-exec redis "$0" "$@" +fi + +exec "$@" diff --git a/redis/image-build/3.2/docker-entrypoint.sh b/redis/image-build/3.2/docker-entrypoint.sh new file mode 100644 index 0000000..c4facfb --- /dev/null +++ b/redis/image-build/3.2/docker-entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +# first arg is `-f` or `--some-option` +# or first arg is `something.conf` +if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then + set -- redis-server "$@" +fi + +# allow the container to be started with `--user` +if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then + chown -R redis . + exec gosu redis "$0" "$@" +fi + +exec "$@"