docker images|grep redis
redis latest 7614ae9453d1 19 months ago 113MB
1.3.2 用docker run启动Redis容器
运行Redis容器:
docker run -itd --name myFirstRedis -p 6379:6379 redis:latest
db18e24f57c664d85897241a248fa0ebace73fe7df321fd2d34307bb2b0291e1
查看结果:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
db18e24f57c6 redis:latest "docker-entrypoint.s…" 18 seconds ago Up 17 seconds 0.0.0.0:6379->6379/tcp myFirstRedis
redis-cli
127.0.0.1:6379> set val 1
OK
127.0.0.1:6379> get val
"1"
退出redis-cli:
127.0.0.1:6379> exit
root@db18e24f57c6:/data#
退出容器:
root@db18e24f57c6:/data# exit
exit
1.3.5 停止、重启和删除Redis容器
停止容器:
docker stop myFirstRedis
myFirstRedis
查看结果:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
db18e24f57c6 redis:latest "docker-entrypoint.s…" 5 minutes ago Exited (0) 28 seconds ago myFirstRedis
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
db18e24f57c6 redis:latest "docker-entrypoint.s…" 20 minutes ago Exited (0) 9 seconds ago myFirstRedis
当通过docker run -itd --name myFirstRedis -p 6379:6379 redis:latest和docker start myFirstRedis这两个命令启动Redis容器后,包含在容器里的Redis服务器会自动启动.