局域网Centos7.6 安装docker并运行redis

安装docker及pull redis错误记录

错误一: yum insert docker-ce提示下载超时或域名无法解决

1)、使用yum命令安装镜像地址使用的是aliyun镜像,执行命令下载包一直提示超时
2)、换成163的镜像地址提示域名解析不了。
解决方法:替换/etc/yum.repos.d/Centos-Base.repo文件主域名为官方镜像mirror.centos.org后正常。

错误二: Error response from daemon: lookup registry-1.docker.io on i/o timeout

[root@localhost ~]# docker pull redis:3.2
Error response from daemon: Get https://registry-1.docker.io/v2/library/redis/manifests/3.2: dial tcp: lookup registry-1.docker.io on 192.168.11.1:53: read udp 192.168.11.124:45053->192.168.11.1:53: i/o timeout
解决方法: https://blog.csdn.net/hahaxu/article/details/80522244

错误三: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

[root@localhost ~]# docker pull redis:3.2
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

解决方法:

$ systemctl daemon-reload
$ sudo service docker restart
$ sudo service docker status (should see active (running))
$ sudo docker run hello-world

错误四: Client.Timeout exceeded while awaiting headers

[root@localhost ~]# docker pull redis:3.2
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

解决方法:
下载官方镜像点的镜像国内访问速度太慢,所以报错,使用加速器就可以解决这个问题
首先打开配置文件daemon.json,如果没有需要自己创建文件:
vim /etc/docker/daemon.json
在文件中加入:

{
    "registry-mirrors":["https://docker.mirrors.ustc.edu.cn"]
}

然后重启守护进程:

sudo systemctl daemon-reload
sudo systemctl restart docker

docker - 设置HTTP/HTTPS 代理
配置方法: https://www.cnblogs.com/atuotuo/p/7298673.html
国内免费代理地址:
https://www.kuaidaili.com/free/

docker安装redis基本命令

查询镜像

docker search redis

拉取官方的镜像

docker pull redis:3.2

查看拉取结果

docker images

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               3.2                 87856cc39862        10 months ago       76MB

启动镜像

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

指定登录密码启动

docker run -p 6379:6379 -v $PWD/data:/data/redis -d redis:3.2 redis-server --requirepass "your passwd" --appendonly yes

指定配置文件启动,配置文件已修改允许外网访问及密码设备

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

相关参数说明

创建对应的数据保存目录 mkdir /data/redis
docker run -p 6379:6379 -v $PWD/data:/data/redis  -d redis:3.2 redis-server --appendonly yes
命令说明:
-p 6379:6379 : 将容器的6379端口映射到主机的6379端口
-v $PWD/data:/data/redis : 将主机中目录下/data/redis挂载到容器的/data
redis-server --appendonly yes : 在容器执行redis-server启动命令,并打开redis持久化配置
--requirepass "your passwd"   设备redis密码
-v $PWD/conf/redis.conf:/data/redis/redis.conf: 将主机/data/redis/redis.conf配置文件挂载到容器下/conf/redis.conf
redis-server /data/redis/redis.conf: 启用新的配置文件

查看容器启动情况

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES
ab20d31dd52a        redis:3.2           "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:6379->6379/tcp   naughty_dewdney

连接redis的几种方式

docker exec -ti ab20d31dd52a redis-cli
docker exec -ti ab20d31dd52a redis-cli -h localhost -p 6379
docker exec -ti ab20d31dd52a redis-cli -h 127.0.0.1 -p 6379
docker exec -ti ab20d31dd52a redis-cli -h 172.17.0.3 -p 6379

查看容器IP

[root@localhost data]# docker inspect ab20d31dd52a | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",

错误信息:driver failed programming external connectivity on endpoint intelligent_cohen

[root@localhost data]# docker run -p 6379:6379  -v $PWD/data:/data -d redis:3.2 redis-server --appendonly yes
4aa10ebdf298f1b0b9d02e39aabae95bbf141383e65ff29db2e51d9aa9ac615f
docker: Error response from daemon: driver failed programming external connectivity on endpoint intelligent_cohen (3453ae3a21af0550db7ea7270d57dc82df952d60beb505b13d996fbfad117835):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 6379 -j DNAT --to-destination 172.17.0.2:6379 ! -i docker0: iptables: No chain/target/match by that name.

解决方案:重启docker
systemctl restart docker

你可能感兴趣的:(Redis,Docker)