1. 程式人生 > >Docker基礎映象安裝iproute

Docker基礎映象安裝iproute

iproute簡介

linux下檢視ip及網絡卡資訊通常使用ifconfig和ip命令,ip命令有取代ifconfig命令的趨勢,ip命令由iproute2軟體包提供,在大部分docker基礎映象中可能未安裝此軟體包,下面介紹安裝方法。

CentOS安裝iproute

直接安裝即可:

# yum install -y iproute

Ubuntu安裝iproute

建立容器:

    [[email protected] ~]# docker run -d httpd
    [[email protected] ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS               NAMES
    a235b93de057        httpd               "httpd-foreground"   15 seconds ago      Up 14 seconds       80/tcp              eloquent_visvesvaraya

進入容器:

[[email protected] ~]# docker exec -it a235b93de057 bash
[email protected]:/usr/local/apache2# 

更新,一定要執行更新,否則無法安裝:

[email protected]:/usr/local/apache2# apt-get update 

安裝iproute

[email protected]:/usr/local/apache2# apt-get install iproute

執行ip命令測試:

[email protected]
:/usr/local/apache2# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 90: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0 valid_lft forever preferred_lft forever