Quick build container by docker redis command
First, download the redis
image, use the 5.0.7
version:
docker pull redis:5.0.7
By docker image inspect redis:5.0.7
we can see the data container is present /data
inside.
We create a directory and save the data in the host machine redis
directory configuration file:
# 创建保存数据的目录
mkdir -p /home/docker/redis/data
# 创建保存redis配置文件的目录
mkdir -p /home/docker/redis/conf
In the /home/docker/redis/conf
Create the following redis.conf
profile:
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 redis
container 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
-p
Port Mapping-v
Mounting data volumes-d
Background process--name
Aliasredis-server
Start reading and specify/etc/redis/redis.conf
the configuration
Use redis client tools to connect:
连接ip:宿主机的ip
连接端口:6379
连接密码:requirepass后边设置的字符串