Docker install Redis
Method 1. Build through Dockerfile
Create Dockerfile
First, create the directory redis to store later related things.
php@php:~$ mkdir -p ~/redis ~/redis/data
The data directory will be mapped to the /data directory configured by the redis container as the storage directory for redis data persistence
Enter the created redis directory and create a Dockerfile
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 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.0 ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-3.2.0.tar.gz ENV REDIS_DOWNLOAD_SHA1 0c1820931094369c8cc19fc1be62f598bc5961ca # for redis-sentinel see: http://redis.io/topics/sentinel RUN buildDeps='gcc libc6-dev make' \ && set -x \ && 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_SHA1 *redis.tar.gz" | sha1sum -c - \ && mkdir -p /usr/src/redis \ && tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \ && rm redis.tar.gz \ && 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" ]
Pass Dockerfile creates a mirror and replaces it with your own name
php@php:~/redis$ docker build -t redis:3.2 .
After the creation is completed, we can find the just created mirror in the local mirror list
php@php:~/redis$ docker images redis REPOSITORY TAG IMAGE ID CREATED SIZE redis 3.2 43c923d57784 2 weeks ago 193.9 MB
Method 2, docker pull redis: 3.2
Find the redis image on Docker Hub
php@php:~/redis$ docker search redis NAME DESCRIPTION STARS OFFICIAL AUTOMATED redis Redis is an open source ... 2321 [OK] sameersbn/redis 32 [OK] torusware/speedus-redis Always updated official ... 29 [OK] bitnami/redis Bitnami Redis Docker Image 22 [OK] anapsix/redis 11MB Redis server image ... 6 [OK] webhippie/redis Docker images for redis 4 [OK] clue/redis-benchmark A minimal docker image t... 3 [OK] williamyeh/redis Redis image for Docker 3 [OK] unblibraries/redis Leverages phusion/baseim... 2 [OK] greytip/redis redis 3.0.3 1 [OK] servivum/redis Redis Docker Image 1 [OK] ...
Here we pull the official image, labeled 3.2
php@php:~/redis$ docker pull redis:3.2
After the download is completed, we can mirror it locally The mirror with REPOSITORY redis and label 3.2 is found in the list.
Use redis image
Run the container
php@php:~/redis$ docker run -p 6379:6379 -v $PWD/data:/data -d redis:3.2 redis-server --appendonly yes 43f7a65ec7f8bd64eb1c5d82bc4fb60e5eb31915979c4e7821759aac3b62f330 php@php:~/redis$
Command description:
-p 6379:6379:Modify the container The 6379 port is mapped to the 6379 port of the host
-v $PWD/data:/data:Mount the data in the current directory in the host to the container's /data
redis-server --appendonly yes :Execute the redis-server startup command in the container and open the redis persistence configuration
View the container startup status
php@php:~/redis$ docker ps CONTAINER ID IMAGE COMMAND ... PORTS NAMES 43f7a65ec7f8 redis:3.2 "docker-entrypoint.sh" ... 0.0.0.0:6379->6379/tcp agitated_cray
Connection, View the container
Use the redis image to execute the redis-cli command to connect to the newly started container. The host IP is 172.17.0.1
php@php:~/redis$ docker run -it redis:3.2 redis-cli -h 172.17.0.1 172.17.0.1:6379> info # Server redis_version:3.2.0 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:f449541256e7d446 redis_mode:standalone os:Linux 4.2.0-16-generic x86_64 arch_bits:64 multiplexing_api:epoll ...