【docker构建】基于docker搭建redis数据库缓存服务

搭建redis服务

首先拉取镜像==》运行镜像为容器

# 先搜索下redis镜像
[root@VM_0_10_centos wordpress]# docker search redis

# 拉取镜像(不接版本,默认拉取最新版本)
[root@VM_0_10_centos wordpress]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
000eee12ec04: Pull complete 
5cc53381c195: Pull complete 
48bb7bcb5fbf: Pull complete 
ef8a890bb1c2: Pull complete 
32ada9c6fb0d: Pull complete 
76e034b0f296: Pull complete 
Digest: sha256:1eedfc017b0cd3e232878ce38bd9328518219802a8ef37fe34f58dcf591688ef
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest

# 查看images
[root@VM_0_10_centos wordpress]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
redis                     latest              dcf9ec9265e0        10 days ago         98.2MB

运行容器

# 运行容器,外部端口6378 内部端口6379
[root@VM_0_10_centos wordpress]# docker run -itd -p 6378:6379 --name redis redis
6a9eef9b4fdec813decb690456321b56bec3a0e00fd4c3a0fbc5dfc78697c533

# 查看容器
[root@VM_0_10_centos wordpress]# docker ps 
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS        
                           NAMES6a9eef9b4fde        redis                     "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        0.0.0.0:6378
->6379/tcp

进入容器查看

[root@VM_0_10_centos wordpress]# docker exec -it redis bash
root@6a9eef9b4fde:/data# redis-cli 
127.0.0.1:6379> ls

进行测试。redis是以键值对方式存数据的(redis默认有16个数据库,0-15)

root@6a9eef9b4fde:/data# redis-cli
127.0.0.1:6379> set color green  # 设置键值对
OK
127.0.0.1:6379> get color  # 通过键获取值
"green"
127.0.0.1:6379> keys *  # 获取键列表
1) "color"

 

 

 

 

 

 

posted @ 2019-12-04 11:59  HeiDi_BoKe  阅读(563)  评论(0编辑  收藏  举报