配置国内的源
> /etc/docker/daemon.json
{
"registry-mirrors" : [
"https://mirror.ccs.tencentyun.com",
"http://registry.docker-cn.com",
"http://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
],
"debug" : true,
"experimental" : true
}
重启docker使配置生效
systemctl restart docker
登陆docker仓库 https://hub.docker.com
搜索redis
选择4.0版本
下载Redis测试
[root@test4 doc]# docker pull redis:4.0
4.0: Pulling from library/redis
54fec2fa59d0: Pull complete
9c94e11103d9: Pull complete
04ab1bfc453f: Pull complete
7988789e1fb7: Pull complete
8ce1bab2086c: Pull complete
40e134f79af1: Pull complete
Digest: sha256:2e03fdd159f4a08d2165ca1c92adde438ae4e3e6b0f74322ce013a78ee81c88d
Status: Downloaded newer image for redis:4.0
docker.io/library/redis:4.0
查看镜像列表
[root@test4 doc]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 4.0 191c4017dcdd 3 months ago 89.3MB
删除镜像
方法1
docker image rm 镜像名:版本号
[root@test4 doc]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 4.0 191c4017dcdd 3 months ago 89.3MB
[root@test4 doc]# docker image rm redis:4.0
Untagged: redis:4.0
Untagged: redis@sha256:2e03fdd159f4a08d2165ca1c92adde438ae4e3e6b0f74322ce013a78ee81c88d
Deleted: sha256:191c4017dcdd3370f871a4c6e7e1d55c7d9abed2bebf3005fb3e7d12161262b8
Deleted: sha256:c608627e4978ced00e2f061ae0386fab2e374376b96512bbbd2eea112b1c18ec
Deleted: sha256:3fb5c9513585182e703038a67d9aaac987d4be30b6d3ece92ffe35734b330500
Deleted: sha256:e3a7fbb7bf3b4de87e6765498bf952b114f9bf297e5e93f51bd6a9a32083f8e4
Deleted: sha256:09f9b5d7722b181ae2acd61396c20549afdea66ee31f921850191db5afe6738a
Deleted: sha256:3bd2921d0d3dd52dbcdc462f35b11cb89df901205284b0fea03c19bb8359907a
Deleted: sha256:c2adabaecedbda0af72b153c6499a0555f3a769d52370469d8f6bd6328af9b13
方法2
[root@test4 doc]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 4.0 191c4017dcdd 3 months ago 89.3MB
[root@test4 doc]# docker rmi 191c4017dcdd
Untagged: redis:4.0
Untagged: redis@sha256:2e03fdd159f4a08d2165ca1c92adde438ae4e3e6b0f74322ce013a78ee81c88d
Deleted: sha256:191c4017dcdd3370f871a4c6e7e1d55c7d9abed2bebf3005fb3e7d12161262b8
Deleted: sha256:c608627e4978ced00e2f061ae0386fab2e374376b96512bbbd2eea112b1c18ec
Deleted: sha256:3fb5c9513585182e703038a67d9aaac987d4be30b6d3ece92ffe35734b330500
Deleted: sha256:e3a7fbb7bf3b4de87e6765498bf952b114f9bf297e5e93f51bd6a9a32083f8e4
Deleted: sha256:09f9b5d7722b181ae2acd61396c20549afdea66ee31f921850191db5afe6738a
Deleted: sha256:3bd2921d0d3dd52dbcdc462f35b11cb89df901205284b0fea03c19bb8359907a
Deleted: sha256:c2adabaecedbda0af72b153c6499a0555f3a769d52370469d8f6bd6328af9b13
镜像迁移
将镜像打包成文件
docker save 镜像名称 | gzip > alpine-latest.tar.gz
将文件加载到docker
docker load -i alpine-latest.tar.gz
Docker Redis 使用
启动redis
# 控制台启动redis
# -d 是后台运行
# -p :端口映射(-p 80:80)80端口映射到外部的80端口上,前一个是映射,后一个容器内的端口
docker run -p 6379:6379 [-d] redis:4.0 redis-server
查看docker启动的服务
[root@test4 ]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0cab60f2e5ae redis:4.0 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:6379->6379/tcp elegant_stonebraker
调用客户端使用服务
# 0cab60f2e5ae 是docker运行的 CONTAINER ID
# /bin/bash 是进入容器,可以使用bash命令,比如使用redis-cli.sh
[root@test4 doc]# docker exec -it 0cab60f2e5ae /bin/bash
root@0cab60f2e5ae:/data# redis-cli
127.0.0.1:6379> KEYS *
(empty list or set)
127.0.0.1:6379> set 1 1
OK
127.0.0.1:6379> get 1
"1"
127.0.0.1:6379>
查看容器日志
docker logs -f 容器名称/容器ID
启动和停止容器
启动和停止容器中的数据不会变化,如果停止后再次执行 docker run -p 6379:6379 -d redis:4.0 redis-server 则会产生新的容器
单独执行 stop start 指定的容器是不会发生变化
docker container stop 容器名称/容器ID
docker container start 容器名称/容器ID
删除容器
删除之后就不能进行容器启动和停止了
docker container rm 容器ID
标签:容器,入门,Deleted,redis,使用,docker,sha256,Docker,4.0 From: https://blog.51cto.com/u_13721902/6249925