手册
https://hub.docker.com/_/redis?tab=description&page=1&ordering=last_updated
下载镜像
docker pull redis
![image.png](https://img-blog.csdnimg.cn/img_convert/ba5b67465fee23808fdc9b3cec19175d.png#align=left&display=inline&height=282&margin=[object Object]&name=image.png&originHeight=282&originWidth=1032&size=41580&status=done&style=none&width=1032)
启动redis
[root@localhost ~]# mkdir -p /mydata/redis/conf
[root@localhost ~]# touch /mydata/redis/conf/redis.conf
[root@localhost ~]# echo "appendonly yes" >> /mydata/redis/conf/redis.conf
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 a70d36bc331a 10 days ago 449MB
redis latest 621ceef7494a 2 weeks ago 104MB
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 a70d36bc331a 10 days ago 449MB
redis latest 621ceef7494a 2 weeks ago 104MB
[root@localhost ~]# docker run -p 6379:6379 --name redis \
> -v /mydata/redis/data:/data \
> -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
> -d redis redis-server /etc/redis/redis.conf
9ae543a343ce116c7e02921cbd1fead34219c83c04e4e1c5cff87f7d1a0c3887
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9ae543a343ce redis "docker-entrypoint.s…" 9 seconds ago Up 7 seconds 0.0.0.0:6379->6379/tcp redis
74b1ffa8d7d8 mysql:5.7 "docker-entrypoint.s…" 42 minutes ago Up 38 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
测试是否可用
docker exec -it redis redis-cli
[root@localhost ~]# docker exec -it redis redis-cli
127.0.0.1:6379> set a b
OK
127.0.0.1:6379> get a
"b"
127.0.0.1:6379> exit
![image.png](https://img-blog.csdnimg.cn/img_convert/44fbed2752d538221bd387070342c1d0.png#align=left&display=inline&height=273&margin=[object Object]&name=image.png&originHeight=273&originWidth=937&size=30575&status=done&style=none&width=937)
设置redis容器在docker启动的时候启动
[root@localhost ~]# docker update redis --restart=always
redis