docker容器中不能ping
- 描述
docker exec -it deac /bin/bash
bash-4.3$ ping 192.168.1.100
PING 192.168.1.100 (192.168.10.100): 56 data bytes
ping: permission denied (are you root?)
- 首先,查看当前用户
bash-4.3$ whoami
jenkins
- 然后,再看看文件权限
# 查看ping权限
bash-4.3# ls -lsh /bin/ping
0 lrwxrwxrwx 1 root root 12 May 9 2017 /bin/ping -> /bin/busybox
#查看ping连接文件的权限
bash-4.3$ ls -lhs /bin/busybox
804K -rwr-xr-x 1 root root 803K Oct 26 2016 /bin/busybox
- 方法一,临时方式,以root用户登录
docker exec -u root -it deac /bin/bash
- 方法二,永久,添加s权限
#添加权限
chmod u+s /bin/ping # 让用户在执行ping时,暂时拥有权限
#再查看权限
bash-4.3$ ls -lsh /bin/busybox
804K -rwsr-xr-x 1 root root 803K Oct 26 2016 /bin/busybox
此生必看的科学实验-水知道答案