1.官方网址
https://hub.docker.com/_/redis/
====================================================================
2. 拉取官方镜像
(1) docker pull redis:5.0.6
(2)查看镜像详情:docker run -it --rm --entrypoint=/bin/sh redis:5.0.6
(3)入口:docker-entrypoint.sh redis-server
====================================================================
3.准备配置文件到宿主机以便于挂载(镜像中并没有配置文件存在)
(1)mkdir -p /etc/redis
(2)touch -c /etc/redis/redis.conf
====================================================================
4. 运行镜像
(1)在文件docker-compose.yml中添加运行项,再运行:docker-compose up -d redis
redis:
image: redis:5.0.6
container_name: redis
privileged: false
ports:
- 6379:6379
restart: always
volumes:
- /var/lib/redis:/data
- /etc/redis/redis.conf:/etc/redis/redis.conf
command: redis-server /etc/redis/redis.conf
-----------------------------------------------------------------------------------------------------------------------
(2)直接运行:
docker run --name redis -d -p 6379:6379 --restart always -v /var/lib/redis:/data -v /etc/redis/redis.conf:/etc/redis/redis.conf redis:5.0.6 redis-server /etc/redis/redis.conf
(3)docker容器内操作redis:
->redis-cli
->keys *token*
->ttl key,查看key的过期时间