Docker - Ubuntu - bash: ping: comando no encontrado

Resuelto Snowcrash asked hace 7 años • 8 respuestas

Tengo un contenedor Docker que ejecuta Ubuntu y lo hice de la siguiente manera:

docker run -it ubuntu /bin/bash

sin embargo no parece tenerlo ping. P.ej

bash: ping: command not found

¿Necesito instalar eso?

Parece que falta un comando bastante básico. Lo intenté whereis pingy no informa nada.

Snowcrash avatar Oct 06 '16 23:10 Snowcrash
Aceptado

Las imágenes de Docker son bastante mínimas, pero puedes instalarlas pingen tu imagen oficial de Docker de Ubuntu a través de:

apt-get update -y
apt-get install -y iputils-ping

Lo más probable es que no la necesite pingen su imagen y solo quiera usarla con fines de prueba. El ejemplo anterior te ayudará.

Pero si necesita pingexistir en su imagen, puede crear un contenedor Dockerfileo commitel contenedor en el que ejecutó los comandos anteriores en una nueva imagen.

Comprometerse:

docker commit -m "Installed iputils-ping" --author "Your Name <[email protected]>" ContainerNameOrId yourrepository/imagename:tag

Archivo Docker:

FROM ubuntu
RUN apt-get update && apt-get install -y iputils-ping
CMD bash

Tenga en cuenta que existen mejores prácticas para crear imágenes de Docker, como borrar archivos de caché de apt después, etc.

Farhad Farahi avatar Oct 06 '2016 16:10 Farhad Farahi

Esta es la página de Docker Hub para Ubuntu y así es como se crea. Solo tiene instalados (algo) paquetes mínimos, por lo que si necesita algo adicional, debe instalarlo usted mismo.

apt-get update && apt-get install -y iputils-ping

Sin embargo, normalmente crearías un "Dockerfile" y lo compilarías:

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

Utilice Google para buscar tutoriales y explorar los Dockerfiles existentes para ver cómo suelen hacer las cosas :) Por ejemplo, el tamaño de la imagen debe minimizarse ejecutando apt-get clean && rm -rf /var/lib/apt/lists/*después de apt-get installlos comandos.

NikoNyrh avatar Oct 06 '2016 16:10 NikoNyrh

Alternativamente, puedes usar una imagen de Docker que ya tenga ping instalado, por ejemplo, Busybox :

docker run --rm busybox ping SERVER_NAME -c 2
Ivan avatar Sep 13 '2018 11:09 Ivan