How to Install and Use ifconfig in Ubuntu Docker Containers: Missing net-tools Package Explained


2 views

When spinning up a basic ubuntu:12.04 container, many developers are surprised to find the ifconfig command missing. This isn't a bug - it's a deliberate design choice in modern containerization. The traditional network configuration tool was excluded to keep the image size minimal.

The container includes the newer ip command from the iproute2 package because:

  • It's more powerful and flexible for modern networking needs
  • Maintained as part of the core Linux networking stack
  • Smaller footprint than the entire net-tools suite

To get ifconfig functionality, you'll need to install the net-tools package:

# For Ubuntu/Debian containers:
apt-get update && apt-get install -y net-tools

# For CentOS/RHEL containers:
yum install -y net-tools

Here's how to create a custom image with ifconfig pre-installed:

FROM ubuntu:12.04
RUN apt-get update && \
    apt-get install -y net-tools && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

While you can install ifconfig, consider using these newer approaches:

# Basic network info:
ip addr show

# Route information:
ip route show

# Interface statistics:
ip -s link

When working with Ubuntu-based Docker containers (especially older versions like ubuntu:12.04), you might notice that the familiar ifconfig command isn't available, while ip command works fine. This isn't a bug - it's a deliberate design choice.

The net-tools package (which provides ifconfig) has been deprecated in favor of the iproute2 suite (which provides ip) in modern Linux distributions. Docker images are typically minimized to reduce size, so they exclude deprecated packages by default.

If you specifically need ifconfig (perhaps for legacy scripts), you can easily install it:

# For Ubuntu/Debian-based containers:
apt-get update
apt-get install -y net-tools

# For CentOS/RHEL-based containers:
yum install -y net-tools

Here's how you might include this in a Dockerfile:

FROM ubuntu:12.04
RUN apt-get update && \
    apt-get install -y net-tools && \
    apt-get clean

Consider using the modern ip command instead. Here's a quick comparison:

# Old way:
ifconfig eth0

# Modern equivalent:
ip addr show eth0

Understanding these package differences helps when:

  • Debugging container networking
  • Migrating legacy scripts to containers
  • Creating minimal yet functional images