I've got a Docker container running Ubuntu which I did as follows:
docker run -it ubuntu /bin/bash
however it doesn't seem to have ping
. E.g.
bash: ping: command not found
Do I need to install that?
Seems a pretty basic command to be missing. I tried whereis ping
which doesn't report anything.
This is the Docker Hub page for Ubuntu and this is how it is created. It only has (somewhat) bare minimum packages installed, thus if you need anything extra you need to install it yourself.
However usually you'd create a "Dockerfile" and build it:
Please use Google to find tutorials and browse existing Dockerfiles to see how they usually do things :) For example image size should be minimized by running
apt-get clean && rm -rf /var/lib/apt/lists/*
afterapt-get install
commands.Alternatively you can use a Docker image which already has ping installed, e.g. busybox:
Docker images are pretty minimal, But you can install
ping
in your official ubuntu docker image via:Chances are you dont need
ping
your image, and just want to use it for testing purposes. Above example will help you out.But if you need ping to exist on your image, you can create a
Dockerfile
orcommit
the container you ran the above commands in to a new image.Commit:
Dockerfile:
Please note there are best practices on creating docker images, Like clearing apt cache files after and etc.
Generally people pull the official image of Ubuntu/CentOS but they don't realize that these images are minimal and doesn't have any thing on the top of that.
For Ubuntu, this image is built from official rootfs tarballs provided by Canonical. Given that it is a minimal install of Ubuntu, this image only includes the C, C.UTF-8, and POSIX locales by default.
One can install net-tools (includes ifconfig, netstat), ip-utils(includes ping) andy other likes curl etc on container and can create image from container or can write Dockerfile that will install these tool while creating image.
Below is Dockerfile example, while creating image from this it will include these tools:
or launch container from base image and install these utilities on container and then commit to image. docker commit -m "any descriptive message" container_id image_name:lattest
That image will have all thing installed.