docker container quickly build redis

Quick build container by docker redis command

First, download the redisimage, use the 5.0.7version:

docker pull redis:5.0.7

By docker image inspect redis:5.0.7we can see the data container is present /datainside.

We create a directory and save the data in the host machine redisdirectory configuration file:

# 创建保存数据的目录
mkdir -p /home/docker/redis/data
# 创建保存redis配置文件的目录
mkdir -p /home/docker/redis/conf

In the /home/docker/redis/confCreate the following redis.confprofile:

cd /home/docker/redis/conf
touch redis.conf
vi redis.conf

Fill in the following configuration:

# 允许远程访问
bind 0.0.0.0
protected-mode no
# 连接密码
requirepass password

Create a rediscontainer named my-redis:

docker run -p 6379:6379 -v /home/docker/redis/data:/data -v /home/docker/redis/conf/redis.conf:/etc/redis/redis.conf -d --name=my-redis redis:5.0.7 redis-server /etc/redis/redis.conf
  • -pPort Mapping
  • -vMounting data volumes
  • -dBackground process
  • --nameAlias
  • redis-serverStart reading and specify /etc/redis/redis.confthe configuration

Use redis client tools to connect:

连接ip:宿主机的ip
连接端口:6379
连接密码:requirepass后边设置的字符串
Published 181 original articles · won praise 154 · views 620 000 +

Guess you like

Origin blog.csdn.net/hbtj_1216/article/details/104735294