ChatGPT解决这个技术问题 Extra ChatGPT

ip command is missing from ubuntu docker image

when i'm trying to perform ip command in ubuntu docker container, i'm getting:

bash: ip: command not found.

ubuntu version:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"

what package should i install for that command?

Thanks


C
Community

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.

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

But to use apt-file you first need to install and update its cache: $ apt-get install apt-file then: $ apt-file update
p
prosti

Don't forget to install the iproute2

apt install iproute2

And then you may use ip command.


Do you mean from inside the container ? How would I do that if there's no network to download anything ?
This process assumes you have Internet connection I have no idea how to do it without connection.
On ubuntu 18 host and guest. I have working connection on host, I have masquerade set in iptables, I have bridge docker0 set up all automatically. apt update in container is not working, ip, ping, route, ifconfig commands are missing, /etc/network/interfaces file is missing.
Not necessary. We can execute chroot rootfs_dir and then apt install iproute2. @Pavel Niedoba
This is only a subset of the existing answer posted one year before and does not bring any new information.
P
Peter Csala

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

This is not correct. ip is not part of net-tools
Yes, its used for "ifconfig" command