How to install “ifconfig” command in my ubuntu docker image?

前端 未结 9 1239
后悔当初
后悔当初 2021-01-30 02:50

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 i

相关标签:
9条回答
  • 2021-01-30 03:18

    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.

    0 讨论(0)
  • 2021-01-30 03:20

    write

    sudo apt-get install net-tools

    0 讨论(0)
  • 2021-01-30 03:25

    Please use the below command to get the IP address of the running container.

    $ ip addr
    

    Example-:

    root@4c712d05922b:/# ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
        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
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever
    247: eth0@if248: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
        link/ether 02:42:ac:11:00:06 brd ff:ff:ff:ff:ff:ff link-netnsid 0
        inet 172.17.0.6/16 scope global eth0
           valid_lft forever preferred_lft forever
        inet6 fe80::42:acff:fe11:6/64 scope link
           valid_lft forever preferred_lft forever
    
    0 讨论(0)
  • 2021-01-30 03:28

    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.

    0 讨论(0)
  • 2021-01-30 03:28

    If Ubuntu Docker image isn't recognizing 'ifconfig' inside of GNS3, you'll need to open Ubuntu docker image on your host.

    Assuming you already have docker on your host pc and ubuntu pull'd from docker images. Enter these commands in your host OS (Linux, CentOS, etc.) CLI.

    $docker images
    
    $docker run -it ubuntu
    
    $apt-get update
    
    $apt-get install net-tools
    

    (side note: you can add whatever other tools and services that you would like to add now, but for now this is just to get ifconfig to work.)

    $exit
    

    Now you will commit these changes to Docker. This link for committing changes is the best summary and works (skip to Step 4):

    https://phoenixnap.com/kb/how-to-commit-changes-to-docker-image#htoc-step-3-modify-the-container

    When you re-open the docker image in GNS3 you should now have the ifconfig command usable and whatever other tools or services you added to the container.

    Enjoy!

    0 讨论(0)
  • 2021-01-30 03:32

    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.

    0 讨论(0)
提交回复
热议问题