Sno*_*ash 272 ubuntu ping docker
我有一个运行Ubuntu的Docker容器,我按如下方式执行:
docker run -it ubuntu /bin/bash
Run Code Online (Sandbox Code Playgroud)
但它似乎没有ping.例如
bash: ping: command not found
Run Code Online (Sandbox Code Playgroud)
我需要安装吗?
似乎缺少一个非常基本的命令.我试过whereis ping没报告任何事情.
Far*_*ahi 559
Docker镜像非常小,但您可以ping通过以下方式安装在官方的ubuntu docker镜像中:
apt-get update
apt-get install iputils-ping
Run Code Online (Sandbox Code Playgroud)
您可能不需要ping您的图像,只是想将其用于测试目的.以上示例将帮助您.
但是,如果您的图像上需要ping,则可以创建一个Dockerfile或commit您运行上述命令的容器到新图像.
承诺:
docker commit -m "Installed iputils-ping" --author "Your Name <name@domain.com>" ContainerNameOrId yourrepository/imagename:tag
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get install -y iputils-ping
CMD bash
Run Code Online (Sandbox Code Playgroud)
请注意,有关于创建docker镜像的最佳实践,例如清除之后的apt缓存文件等.
Nik*_*yrh 25
这是Ubuntu的Docker Hub页面,这就是它的创建方式.它只有(有些)安装了最小的包,因此如果你需要额外的东西,你需要自己安装它.
apt-get update && apt-get install -y iputils-ping
Run Code Online (Sandbox Code Playgroud)
但是通常你会创建一个"Dockerfile"并构建它:
mkdir ubuntu_with_ping
cat >ubuntu_with_ping/Dockerfile <<'EOF'
FROM ubuntu
RUN apt-get update && apt-get install -y iputils-ping
CMD bash
EOF
docker build -t ubuntu_with_ping ubuntu_with_ping
docker run -it ubuntu_with_ping
Run Code Online (Sandbox Code Playgroud)
请使用谷歌找到的教程和浏览现有Dockerfiles,看看他们平时是怎么做的事情:)例如图像大小应通过运行最小化apt-get clean && rm -rf /var/lib/apt/lists/*之后apt-get install的命令.
通常,人们会使用Ubuntu / CentOS的官方映像,但他们没有意识到这些映像是最小的,并且最重要的是没有。
对于Ubuntu,此映像是由Canonical提供的官方rootfs tarball构建的。鉴于它是Ubuntu的最小安装,因此默认情况下,该映像仅包含C,C.UTF-8和POSIX语言环境。
可以在容器上安装net-tools(包括ifconfig,netstat),ip-utils(包括ping)和其他类似curl的工具,可以从容器创建映像,也可以编写Dockerfile来在创建映像时安装这些工具。
以下是Dockerfile示例,从中创建映像时,它将包括以下工具:
FROM vkitpro/ubuntu16.04
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install iputils-ping -y \
&& apt-get install net-tools -y \
CMD bash
Run Code Online (Sandbox Code Playgroud)
或从基本映像启动容器,然后将这些实用程序安装在容器上,然后提交到映像。docker commit -m“任何描述性消息” container_id image_name:lattest
该映像将安装所有东西。
或者,您可以使用已经安装了ping的Docker映像,例如busybox:
docker run --rm busybox ping SERVER_NAME -c 2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
282141 次 |
| 最近记录: |