1.拉取redis镜像
sudo docker pull redis:6.0
2.检查redis镜像拉取结果,此时已看到已经拉取成功:
root@ubuntu-xenial:/# docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis 6.0 235592615444 4 weeks ago 104MB mysql 5.7 9cfcce23593a 4 weeks ago 448MB
3.使用镜像启动一个redis运行实例:
3.1在启动之前首先需要将配置文件映射的文件目录创建好,这里有个坑,如果不提前创建,则会将文件名称识别为文件夹名
sudo mkdir -p /mydata/redis/conf sudo touch /mydata/redis/conf/redis.conf
3.2配置redis持久化开关(配置内容:“appendonly yes”):默认配置文件:https://raw.githubusercontent.com/redis/redis/6.0/redis.conf
sudo vi /mydata/redis/conf/redis.conf
3.2.启动一个实例,并将配置映射指定好:
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf -d redis:6.0 redis-server /etc/redis/redis.conf
4.查看redis镜像启动情况:
root@ubuntu-xenial:/# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1c6c2945ea07 redis:6.0 "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:6379->6379/tcp redis ba385514ac90 mysql:5.7 "docker-entrypoint.s…" 2 hours ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
5.使用容器id(“0bd04790d4ee”为CONTAINER ID)设置redis随docker启动:
sudo docker update 0bd04790d4ee --restart=always