Docker-Ubuntu-bash:ping:找不到命令 [英] Docker - Ubuntu - bash: ping: command not found
问题描述
我有一个运行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 dont need ping
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 in to 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 after and etc.
这篇关于Docker-Ubuntu-bash:ping:找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!