Docker - Ubuntu - bash: ping: 命令未找到 [英] Docker - Ubuntu - bash: ping: command not found

查看:73
本文介绍了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 存在于您的图像中,您可以创建一个 Dockerfilecommit 将上述命令运行到的容器一张新图片.

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.

这篇关于Docker - Ubuntu - bash: ping: 命令未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆