当我在Ubuntu的Docker容器中尝试执行IP命令时,我收到以下错误信息:
bash: ip: 命令未找到。
Ubuntu版本:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
我应该安装哪个软件包来运行那个命令?
谢谢!
你可以使用 apt-file search
命令来确定包含所需命令的软件包。在我的ubuntu16.04上,它告诉我需要安装 iproute2
,我认为在1804版本中也是相似的。
1. 获取需要安装的软件包:
$ apt-file search --regexp 'bin/ip$'
iproute2: /bin/ip
iproute2: /sbin/ip
2. 安装该软件包:
$ apt install -y iproute2
...
3. 确认软件包已安装:
$ dpkg -l iproute2
ii iproute2 4.3.0-1ubuntu3 amd64 networking and traffic control tools
不要忘记安装iproute2
apt install iproute2
然后您可以使用 ip
命令。
chroot rootfs_dir
,然后安装 iproute2
。@Pavel Niedoba - Mahler希望它能有所帮助:
root@458517c8d93f:/# ip a
bash: ip: command not found
root@458517c8d93f:/# ifconfig
bash: ifconfig: command not found
root@458517c8d93f:/etc/systemd/network# apt-get install net-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
net-tools
0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded.
Need to get 194 kB of archives.
After this operation, 803 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 net-tools amd64 1.60+git20161116.90da8a0-1ubuntu1 [194 kB]
Fetched 194 kB in 3s (69.0 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package net-tools.
(Reading database ... 9962 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20161116.90da8a0-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20161116.90da8a0-1ubuntu1) ...
Setting up net-tools (1.60+git20161116.90da8a0-1ubuntu1) ...
root@458517c8d93f:/etc/systemd/network# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.4 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe12:4 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:12:00:04 txqueuelen 0 (Ethernet)
RX packets 21578 bytes 54216887 (54.2 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 19156 bytes 1057383 (1.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 16 bytes 2100 (2.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 2100 (2.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ifconfig
但不能安装 ip
。 - Luke Briner一旦您使用最新版本的Ubuntu或任何版本的映像创建了Docker并创建了一个Ubuntu容器,您必须运行Ubuntu容器并安装以下基本网络命令:
apt-get update
apt-get upgrade
apt-get install -y net-tools
apt-get update
apt-file
,首先需要安装并更新其缓存:$ apt-get install apt-file
然后:$ apt-file update
。 - Alexandro de Oliveiraapt install -y iproute2
中出现Unable to locate package iproute2
。需要先运行apt-get update
。请参阅此处:https://www.devmanuals.net/install/ubuntu/ubuntu-20-04-focal-fossa/installing-iproute2-on-ubuntu20-04.html。 - Chris