1、搜索查找镜像

docker search redis
root@kobe:/opt/software/redis# docker search redis
NAME                                  DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
redis                                 Redis is an open source key-value store that…   4638                [OK]                
bitnami/redis                         Bitnami Redis Docker Image                      66                                      [OK]
sameersbn/redis                                                                       61                                      [OK]
tenstartups/redis-commander                                                           31                                      [OK]
hypriot/rpi-redis                     Raspberry Pi compatible redis image             30                                      
joshula/redis-sentinel                A container for Redis Sentinel                  20                                      
kubeguide/redis-master                redis-master with "Hello World!"                19                                      
kubeguide/guestbook-redis-slave       Guestbook redis slave                           15                                      
webhippie/redis                       Docker images for redis                         7                                       [OK]
rtoma/logspout-redis-logstash         Logspout including Redis adapter for sending…   5                                       
arm32v7/redis                         Redis is an open source key-value store that…   3                                       
gurpartap/redis                       Smallest redis image at 18.56MB, 5.6MB of wh…   3                                       
tomesar/redis-arm                     Redis for ARM!                                  2                                       [OK]
centos/redis-32-centos7               Redis in-memory data structure store, used a…   2                                       
dynomitedb/redis                      Redis backend for DynomiteDB.                   1                                       [OK]
vidazoohub/marathon-redis-autoscale   autoscale worker tasks based on redis size      1                                       [OK]
frodenas/redis                        A Docker Image for Redis                        1                                       [OK]
google/guestbook-python-redis         A simple guestbook example written in Python…   1                                       
iadvize/redis                                                                         0                                       
ajmath/fluentd-redis                  Use fluentd logs to send docker logs to redi…   0                                       [OK]
rediscommander/redis-commander        Alpine image for redis-commander - Redis man…   0                                       [OK]
kilsoo75/redis-master                 This image is for the redis master of SK Clo…   0                                       
brendangibat/docker-logspout-redis    Docker Logspout container with Logspout-Redi…   0                                       [OK]
anchorfree/redis                      redis cache server for logging                  0                                       
sstarcher/fluent-redis-aws            https://github.com/sstarcher/docker-fluent-r…   0                                       [OK]

2、下载镜像

docker pull redis:latest

下载完成后即可查看镜像

3、查看镜像并创建redis和redis/data目录

docker images
root@kobe:/opt/software/redis# docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
redis                          latest              1e70071f4af4        3 weeks ago         107MB

4、使用镜像创建容器

进入redis目录(redis目录下还有data目录,用于redis数据持久化的存储)

docker run -p 6379:6379 -v $PWD/data:/data -d redis:latest redis-server --appendonly yes

-p   6379:6379 :将容器的6379端口映射到主机的6379端口
-v   $PWD/data:/data :将主机中当前目录下的data挂载到容器的/data
redis-server --appendonly yes  在容器执行redis-server启动命令,并打开redis持久化配置

5、进入容器操作redis

docker run -it redis:latest redis-cli -h 192.168.163.170
root@kobe:/opt/software/redis# docker run -it redis:latest redis-cli -h 192.168.163.170
192.168.163.170:6379> info
# Server
redis_version:4.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:f1060815dd32471a
redis_mode:standalone
os:Linux 4.10.0-42-generic x86_64
.................
# Cluster
cluster_enabled:0

# Keyspace
192.168.163.170:6379> exit
root@kobe:/opt/software/redis# 

退出后,重新执行第五步即可重新进入容器操作redis容器

此时使用docker ps即可查看到运行的容器

root@kobe:/opt/software/redis# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                        NAMES
e981e149e349        redis:latest        "docker-entrypoint.s…"   11 minutes ago      Up 11 minutes       0.0.0.0:6379->6379/tcp                       dazzling_kowalevski

 

转载于:https://my.oschina.net/xiaozhiwen/blog/1602628

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐