docker(部署常见应用):docker部署redis
上节回顾:docker(部署常见应用):docker部署mysql
docker部署redis:4.0
# 下载镜像 docker pull redis:4.0 # 查看下载镜像 docker images|grep redis # 启动镜像
docker run --name my-redis -p 16379:6379 -v /usr/local/workspace/redis/data:/data -d redis:4.0 redis-server --appendonly yes
命令说明:
--name my-redis 启动后容器名为 my-redis
-p 16379:3306 将容器的 3306 端口映射到主机的 16379 端口
-v /usr/local/workspace/redis/data:/data 将主机 /usr/local/workspace/redis/data 目录挂载到容器的 /data
redis-server --appendonly yes 在容器执行redis-server启动命令,并打开redis持久化配置
查看容器启动情况
[root@k8s-master docker]# docker ps|grep redis f9eb2360ed36 redis:4.0 "docker-entrypoint.s?? 5 minutes ago Up 5 minutes 0.0.0.0:16379->6379/tcp my-redis
进入redis容器
# 进入redis容器 docker exec -it f9eb2360ed36 bash # 找到redis执行脚本 root@f9eb2360ed36:/usr/local/bin# cd /usr/local/bin/ root@f9eb2360ed36:/usr/local/bin# ls -l total 24528 -rwxrwxr-x 1 root root 374 Jun 11 06:46 docker-entrypoint.sh -rwxr-xr-x 1 root staff 1286720 May 24 2017 gosu -rwxr-xr-x 1 root staff 2628640 Jun 11 06:48 redis-benchmark -rwxr-xr-x 1 root staff 6121232 Jun 11 06:48 redis-check-aof -rwxr-xr-x 1 root staff 6121232 Jun 11 06:48 redis-check-rdb -rwxr-xr-x 1 root staff 2820088 Jun 11 06:48 redis-cli lrwxrwxrwx 1 root staff 12 Jun 11 06:48 redis-sentinel -> redis-server -rwxr-xr-x 1 root staff 6121232 Jun 11 06:48 redis-server # 执行redis-cli命令连接到redis中 root@f9eb2360ed36:/usr/local/bin# ./redis-cli # 展示redis信息 127.0.0.1:6379> info # Server redis_version:4.0.14 redis_git_sha1:00000000 redis_git_dirty:0
感谢支持。感谢观看