Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing netstat on docker linux container

Tags:

I want to install netstat on my Docker container.

I looked here https://askubuntu.com/questions/813579/netstat-or-alternative-in-docker-ubuntu-server-16-04-container so I'm trying to install it like this:

apt-get install net-tools 

However, I'm getting:

Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package net-tools 

So how can I install netstat?

like image 447
octavian Avatar asked Jan 31 '17 15:01

octavian


People also ask

Do I need to install netstat?

On modern systems, the netstat utility comes pre-installed and there's no need to install it. On older systems, however, you are likely to bump into an error when you run the netstat command. Therefore, to install netstat on Linux distributions, run the command.


Video Answer


1 Answers

You need to run apt-get update first to download the current state of the package repositories. Docker images do not include this to save space, and because they'd likely be outdated when you use it. If you are doing this in a Dockerfile, make sure to keep it as a single RUN command so that caching of the layers doesn't cache an old version of the update command with a new package install request:

RUN apt-get update \   && DEBIAN_FRONTEND=noninteractive apt-get install -y \     net-tools \   && apt-get clean \   && rm -rf /var/lib/apt/lists/* 
like image 54
BMitch Avatar answered Sep 27 '22 23:09

BMitch