Install redis on docker

Install redis on docker

Take redis version 6.0.8 as an example:

ready

initial preparation work

  1. Create a data folder for redis to store data in the linux system
cd /usr/local
mkdir docker
cd /usr/local/docker
mkdir data
pwd
  1. Download the redis6.0.8 version package to the local, then unzip and extract the redis.conf file
    Download address: http://download.redis.io/releases/
    Modify the redis.conf file Configuration reference: https://blog.csdn .net/cssweb_sh/article/details/124253599
  2. Upload the locally modified redis.conf file to the server

The command to transfer files to a remote server via ssh:
scp -P port file_name user@ip:/dir_name

If the port of the remote server is 67539 and the IP address is 192.168.1.1, and you want to transfer a file named README.md to the /usr/local/docker/redis directory on the root user on the remote server, then you The command can be written as:

scp -P 67539 ~/Downloads/redis-6.0.8/redis.conf [email protected]:/usr/local/docker/redis
  1. Switch to the linux server to check whether the redis.conf file is uploaded successfully
cd /usr/local/docker/redis
ls

ready to work

Start installing redis in docker: 6.0.8

  1. Start the docker service
systemctl start docker
  1. View existing image packages in docker
docker images
  1. Download redis: 6.0.8 image package
docker pull redis:6.0.8
  1. Check whether the redis image package is downloaded successfully
docker images
  1. Execute the redis startup command
docker run -p 0.0.0.0:6379:6379 --name my_redis -v /usr/local/docker/redis/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/etc/redis/data --restart=always -itd 16ecd2772934 redis-server /etc/redis/redis.conf

Notes on the startup command:
docker run
-p 0.0.0.0:6379:6379 port mapping between docker and host machine
–name my_redis_1 docker container name
-v /usr/local/docker/redis/redis.conf:/etc/redis/redis. conf mount redis.conf file
-v /usr/local/docker/data:/etc/redis/data mount redis persistent data
--restart=always set redis container to start automatically with docker
-itd 16ecd2772934 start image ID via docker images Command to get
redis-server /etc/redis/redis.conf Specify redis configuration file path in docker, and then start redis in the background

  1. Check whether the redis container is started successfully
docker ps

insert image description here

  1. Open a new redis terminal in the container to prevent the container from stopping the next time you exit the container through exit
docker exec -it 15ccfe2fec87 /bin/bash
exit
docker ps

Test whether the redis container is running normally

docker exec -it 15ccfe2fec87 /bin/bash
redis-cli 进入redis终端
auth redis123   验证redis密码
set a 1
get a
del a
exit
exit
docker ps

insert image description here

Guess you like

Origin blog.csdn.net/lu962820662/article/details/129336060