当我试图在 ubuntu docker 容器中执行 ip 命令时,我得到:
找不到命令。
Ubuntu 版本:
DISTRIB_ID=Ubuntu DISTRIB_RELEASE=18.04 DISTRIB_CODENAME=bionic DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
我应该为该命令安装什么软件包?
谢谢
You could use apt-file search to determine the command in which package. From my ubuntu16.04, it tells me to install iproute2, I think 1804 similar.
apt-file search
iproute2
1. Get what package need to be installed:
$ apt-file search --regexp 'bin/ip$' iproute2: /bin/ip iproute2: /sbin/ip
2. Install the package:
$ apt install -y iproute2 ...
3. Verify the package is installed:
$ dpkg -l iproute2 ii iproute2 4.3.0-1ubuntu3 amd64 networking and traffic control tools
Don't forget to install the iproute2
apt install iproute2
And then you may use ip command.
ip
Once you have created your docker with ubuntu latest or any of version image and crated a ubuntu container, you have to run your ubuntu container and install the following for the basic networking command,
apt-get update apt-get upgrade apt-get install -y net-tools apt-get update
I hope it could help:
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