# 常见问题 ## docker命令要用sudo才可以正常执行问题 将当前登录的用户添加到docker组中,这样以后在访问docker时就不用在sudo了 1. 查看是否创建docker 组 ``` cat /etc/group | grep docker ``` 2.创建docker组,第一步打印出东西证明以前建过,就直接跳过这一步。 ``` sudo groupadd docker ``` 3.将用户添加到docker分组 ``` sudo usermod -aG docker 用户名 ``` 4.查看有没有生效 ``` cat /etc/group ``` 5.重启docker ``` sudo systemctl restart docker ``` 1. 给docker.sock添加权限 ```python sudo chmod a+rw /var/run/docker.sock ``` * 还有一种方法 ```bash sudo group add docker #添加docker用户组 sudo gpasswd -a $USER docker #将登陆用户加入到docker用户组中 newgrp docker #更新用户组 ``` ## 无外网访问权限 安装过程中需要访问外网,如果服务器没有外网访问权限,需要申请。常见的请求地址包括: ``` http://mirror.centos.org https://mirrors.aliyun.com https://production.cloudflare.docker.com https://registry-1.docker.io ``` ## 缺少相关依赖 例:问题信息如下,主要关注“Error:”的描述,把“Error”中提到的包下载安装完毕后,重装docker即可。 ``` Error: Package: 3:docker-ce-18.09.9-3.el7.x86_64 (docker-ce-stable) Requires: container-selinux >= 2:2.74 Error: Package: containerd.io-1.4.12-3.1.el7.x86_64 (docker-ce-stable) Requires: container-selinux >= 2:2.74 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest ``` 解决办法 ``` yum install -y container-selinux ``` 如果出现以下情况说明当前源缺少这个包 ``` Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile No package container-selinux available. Error: Nothing to do ``` 可以通过 ``` rpm -ivh container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm ``` 安装过程中如果还缺少哪些依赖,想办法安装后,重新执行上面的安装命令即可。 安装成功后,重新尝试安装Docker。 ## Docker与iptables冲突 ``` ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -C DOCKER -i docker0 -j RETURN' failed: iptables: Bad rule (does a matching rule exist in that chain?). ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?). ERROR: INVALID_ZONE: docker ``` 检查/etc/docker/daemon.json文件是否存在,如果不存在,就创建 ``` { "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] } ``` 如果存在daemon.json文件,就在文件中添加"iptables"\:false ``` { "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"], "iptables":false } ``` 重新启动docker `systemctl start docker`