bash: ip: command not found in an Ubuntu container means the
iproute2 package is not installed. Run apt-get update and
apt-get install -y iproute2, and ip addr lists the container's
interfaces.
The update comes first: a fresh ubuntu:24.04 container has no package lists,
and an install without them stops with E: Unable to locate package.
The error
docker exec fix10-lc-r1 bash -ic 'ip addr 2>&1'
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
bash: ip: command not found
The first two lines come from starting an interactive shell without a terminal. The
mcr.microsoft.com/dotnet/aspnet:10.0 image printed the same
bash: ip: command not found line.
Why it happens
ip is a program from the iproute2 package, and neither image
tested here includes that package. Bash searched the PATH, found no file
called ip and printed the message; nothing about the network was checked. The container's network itself was fine: after the install the
same container showed an address on eth0.
If you came here because an older guide said ifconfig, that command is
missing too and lives in a different package; see the link at the end.
The fix
docker exec fix10-lc-r1 bash -ic 'apt-get update > /dev/null; echo update-exit=$? 2>&1'
...
update-exit=0
...
docker exec fix10-lc-r1 bash -ic 'apt-get install -y iproute2 > /dev/null; echo install-exit=$? 2>&1'
...
debconf: delaying package configuration, since apt-utils is not installed
install-exit=0
docker exec fix10-lc-r1 bash -ic 'ip -brief addr 2>&1'
...
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0@if452 UP 172.17.0.2/16
The debconf line is a notice; the install returned 0. -brief
prints one line per interface. In a second test container with iproute2
installed, the full form gave four to six lines per interface, and
docker inspect on the host reported the same address on the
bridge network:
docker exec fix10-lc-r6 bash -c 'ip addr 2>&1'
...
2: eth0@if456: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 5e:da:4d:8c:62:b6 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.6/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
docker inspect --format "{{json .NetworkSettings.Networks}}" fix10-lc-r6
{"bridge":{"IPAMConfig":null,...,"Gateway":"172.17.0.1","IPAddress":"172.17.0.6",...}}
Your address will differ. A package installed with docker exec did not
outlive its container in a test with ping (a new container from the same image lacked
the command), while an image built with the update and install in one Dockerfile
RUN line had it; do the same with iproute2.
To check which package a file came from once it is installed, ask dpkg. The ip program
sits under /usr/sbin in this image, and dpkg records it under its short
/bin and /sbin paths, so search for the end of the path:
docker exec fix10-lc-r1 bash -c 'dpkg -S bin/ip bin/ifconfig 2>&1 | grep -E ''bin/(ip|ifconfig)$'''
iproute2: /bin/ip
iproute2: /sbin/ip
net-tools: /sbin/ifconfig
How it was reproduced
The captures were made in containers created from ubuntu:24.04 (Ubuntu
24.04.5 LTS, bash 5.2.21, apt 2.8.3) and mcr.microsoft.com/dotnet/aspnet:10.0
with docker run -d --name ... sleep infinity on Docker Engine 29.9.3, and
the commands were sent with docker exec. The installed package was
iproute2 6.1.0-1ubuntu6.4. The fix10-lc- container names are the
test's own.
Every command was sent from Windows PowerShell 5.1 exactly as shown, with the -c text in single quotes so it reached the container unchanged; a single quote inside that text is written twice, as PowerShell requires.
Frequently asked
- Which package provides the ip command on Ubuntu?
- iproute2. In the test apt-get install -y iproute2 returned 0 and ip -brief addr then listed lo and eth0.
- Why is ip not found in my Docker container?
- The ubuntu:24.04 and aspnet:10.0 images tested here do not include iproute2, so bash finds no ip program on the PATH.
- How do I see a container's IP address?
- Install iproute2 inside it and run ip -brief addr. In the test it printed the eth0 address, and docker inspect showed the same address on the bridge network.
More decoded errors in the Fixes category. The older command has its own post: bash: ifconfig: command not found.