Docker - Ubuntu - bash: ping: 命令未找到
我有一个运行 Ubuntu 的 Docker 容器,我做了如下操作:
I've got a Docker container running Ubuntu which I did as follows:
docker run -it ubuntu /bin/bash
但是它似乎没有ping
.例如
bash: ping: command not found
我需要安装那个吗?
似乎缺少一个非常基本的命令.我试过 whereis ping
它不报告任何东西.
Seems a pretty basic command to be missing. I tried whereis ping
which doesn't report anything.
Docker 镜像非常小,但您可以通过以下方式在您的官方 ubuntu docker 镜像中安装 ping
:
Docker images are pretty minimal, but you can install ping
in your official ubuntu docker image via:
apt-get update
apt-get install iputils-ping
您的图像可能不需要 ping
,而只想将其用于测试目的.上面的例子会帮助你.
Chances are you don't need ping
on your image, and just want to use it for testing purposes. Above example will help you out.
但是如果您需要 ping
存在于您的图像中,您可以创建一个 Dockerfile
或 commit
将上述命令运行到的容器一张新图片.
But if you need ping
to exist on your image, you can create a Dockerfile
or commit
the container you ran the above commands into a new image.
提交:
docker commit -m "Installed iputils-ping" --author "Your Name <name@domain.com>" ContainerNameOrId yourrepository/imagename:tag
Dockerfile:
Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get install -y iputils-ping
CMD bash
请注意创建 docker 镜像的最佳实践,例如之后清除 apt 缓存文件等.
Please note there are best practices on creating docker images, like clearing apt cache files afterwards and etc.