- 查找Docker hub上的redis镜像:
docker search redis
- 拉取官方的镜像:
docker pull redis:3.2
- 查看本地镜像列表:
root@star-PC:/usr/local# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 3.2 87856cc39862 9 months ago 76MB
4.启动容器:
#-p 6379:6379 : 将容器的6379端口映射到主机的6379端口
#-v $PWD/data:/data : 将主机中当前目录下的data挂载到容器的/data
#redis-server --appendonly yes : 在容器执行redis-server启动命令,并打开redis持久化配置
root@star-PC:/usr/local/redis# docker run -p 6379:6379 -v /usr/local/redis/data:/data -d redis:3.2 redis-server --appendonly yes
f940fb0582b22c8e6ca7f2c1cfde901e1879a221d164d9fda62677568ee0a41b
5.查看容器启动情况:
root@star-PC:/usr/local/redis# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f940fb0582b2 redis:3.2 "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 0.0.0.0:6379->6379/tcp admiring_leakey
6.连接查看容器:
root@star-PC:/usr/local/redis# docker exec -it f940fb0582b2 redis-cli
127.0.0.1:6379> keys *
(empty list or set)