How to install “ifconfig” command in my ubuntu doc

2020-05-11 18:11发布

I've just installed ubuntu docker image, when I execute "ifconfig" it says there's no such command, I tried apt-get install by there's no package named "ifconfig"(I can install some other images).

So how to do this? Thanks.

9条回答
干净又极端
2楼-- · 2020-05-11 18:39

sudo apt-get install iproute2 then run ip addr show

it works..

查看更多
ら.Afraid
3楼-- · 2020-05-11 18:44

On a fresh ubuntu docker image, run

apt-get update
apt-get install net-tools

These can be executed by logging into the docker container or add this to your dockerfile to build an image with the same.

查看更多
兄弟一词,经得起流年.
4楼-- · 2020-05-11 18:44

You could also consider:

RUN apt-get update && apt-get install -y iputils-ping

(as Contango comments: you must first run apt-get update, to avoid error with missing repository).

See "Replacing ifconfig with ip"

it is most often recommended to move forward with the command that has replaced ifconfig. That command is ip, and it does a great job of stepping in for the out-of-date ifconfig.

But as seen in "Getting a Docker container's IP address from the host", using docker inspect can be more useful depending on your use case.

查看更多
叼着烟拽天下
5楼-- · 2020-05-11 18:50

From within a Dockerfile something like the following should do the trick:

RUN apt-get update && \
     apt-get install -y net-tools

From memory it's best practice to combine the update and the package installation lines to prevent docker caching the update step which can result in out-dated packages being installed.

Installing it via the CLI or a shell script:

apt-get update && apt-get install net-tools

查看更多
男人必须洒脱
6楼-- · 2020-05-11 18:51

In case you want to use the Docker image as a "regular" Ubuntu installation, you can also run unminimize. This will install a lot more than ifconfig, so this might not be what you want.

查看更多
在下西门庆
7楼-- · 2020-05-11 18:52

write

sudo apt-get install net-tools

查看更多
登录 后发表回答