解决容器无法使用ping命令
1.因为不是root用户拒绝了我bash-5.0$ ping 172.18.0.4PING 172.18.0.4 (172.18.0.4): 56 data bytesping: permission denied (are you root?)#无法直接切换到rootbash-5.0$ su rootsu: must be suid to work properly2.排查ping 命令的位置b
·
1.因为不是root用户拒绝了我
bash-5.0$ ping 172.18.0.4
PING 172.18.0.4 (172.18.0.4): 56 data bytes
ping: permission denied (are you root?)
#无法直接切换到root
bash-5.0$ su root
su: must be suid to work properly
2.排查ping 命令的位置
bash-5.0$ which ping
/bin/ping
#进入bin目录查看ping 权限 发现实际路径在/bin/busybox
bash-5.0$ cd /bin/
bash-5.0$ ls -l ping
lrwxrwxrwx 1 root root 12 May 29 14:20 ping -> /bin/busybox
bash-5.0$ ls -l /bin/busybox
-rwxr-xr-x 1 root root 841288 May 22 06:59 /bin/busybox
3.使用root登录并赋予权限
#也可以一键使用这个命令
$ docker exec -u root 75 chmod u+s /bin/busybox
root@u-55:/etc/docker# docker exec -u root -it 75 sh
/usr/share/zabbix # chmod u+s /bin/busybox
/usr/share/zabbix # ping 172.18.0.3
PING 172.18.0.3 (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.105 ms
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.055 ms
64 bytes from 172.18.0.3: seq=2 ttl=64 time=0.070 ms
4.使用普通用户登录
#ping 也可以使用
root@u-55:/etc/docker# docker exec -it 75 sh
/usr/share/zabbix $ ping 172.18.0.3
PING 172.18.0.3 (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.089 ms
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.055 ms
ps:使用–help查看如何使用root账户进入
root@u-55:/etc/docker# docker exec --help
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
Options:
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a container
-e, --env list Set environment variables
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
更多推荐
已为社区贡献5条内容
所有评论(0)