Install Redis with Docker Official Images

Redis on docker

#Install redis

#Refer to install redis on docker

#Prepared

mkdir -p /z-eyes/redis

cd /z-eyes/redis/

sysctl vm.overcommit_memory=1

echo never > /sys/kernel/mm/transparent_hugepage/enabled

#Secure:

#Required: docker network: ipv4 address 

docker network ls

  ##list networksbridge, host and more

docker network inspect bridge | grep IPv4Address

eg: "IPv4Address": "172.17.0.2/16"

vim redis.conf

  port 32222

  bind 127.0.0.1 172.17.0.2

  pidfile /var/run/redis_32222.pid

  requirepass 432#@DD3_#3@#^&*dda45

  rename-command FLUSHALL ""

  rename-command FLUSHDB ""

  rename-command EVAL ""

  rename-command CONFIG CONFIG_ImeRoGEngLeRTcHMOusearBoentE

  rename-command SHUTDOWN SHUTDOWN_ImeRoGEngLeRTcHMOusearBoentE

  appendonly yes


chmod 644 redis.conf

#Build Redis Dockerfile:

vim Dockerfile

  FROM redis:latest
  
  ENV TZ=Asia/Shanghai
  
  RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
  
  RUN mkdir -p /usr/local/etc/redis/

  COPY redis.conf /usr/local/etc/redis/redis.conf

  EXPOSE 32222

  CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]

docker build . -t some/redis:latest

docker images

#docker run --name redis -p 32222:32222 -d some/redis
docker run --name redis --sysctl net.core.somaxconn=20480 -p 31102:31102 -d safami/redis
docker ps -a

#Manage Redis container and image [option]

docker login --username [your name] --password [your password]

docker push some/redis:latest

docker stop redis
#docker start redis
docker rm redis

docker rmi some/redis

#Local Connect

docker run -it --network host --rm redis redis-cli -p 32222 -a '432#@DD3_#3@#^&*dda45'

docker run -it --network bridge --rm redis redis-cli -h 172.17.0.2 -p 32222 -a '432#@DD3_#3@#^&*dda45'

docker run -it --rm redis redis-cli -h 172.17.0.2 -p 32222 -a '432#@DD3_#3@#^&*dda45'

#connected and test
127.0.0.1:32222> ping

#Remote connect

redis-cli -h host -p 32222 -a '432#@DD3_#3@#^&*dda45'

#Docker run redis Error

#Num.1 Running docker container : iptables: No chain/target/match by that name

sudo iptables -t filter -F

sudo iptables -t filter -X

# restart docker

#Num.2Temporary failure in name resolution redis in docker”

check “docker run -it --network [host] ” or redis-cli -h [172.17.0.2]

#The End

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: