Docker-Ubuntu-bash: ping: comando no encontrado


Tengo un contenedor Docker ejecutando Ubuntu que hice de la siguiente manera:

docker run -it ubuntu /bin/bash

Sin embargo no parece tener ping. Por ejemplo,

bash: ping: command not found

¿Necesito instalar eso?

Parece que falta un comando bastante básico. He intentado whereis ping que no informa nada.

Author: Snowcrash, 2016-10-06

3 answers

Las imágenes de Docker son bastante mínimas, pero puedes instalarlas ping en tu imagen oficial de docker de ubuntu a través de:

apt-get update
apt-get install iputils-ping

Es probable que no necesite ping su imagen, y solo desea usarla para fines de prueba. El ejemplo anterior te ayudará.

Pero si necesita ping para existir en su imagen, puede crear un Dockerfile o commit el contenedor en el que ejecutó los comandos anteriores en una nueva imagen.

Commit:

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

Dockerfile:

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

Tenga en cuenta que hay mejores prácticas en la creación de imágenes de docker, como borrar archivos de caché de apt después y etc.

 262
Author: Farhad Farahi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-31 04:53:23

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

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

Sin embargo, normalmente crearías un "Dockerfile" y lo construirí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 encontrar tutoriales y navegar por los archivos Docker 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 install comando.

 13
Author: NikoNyrh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-06 17:13:58

Alternativamente, puede usar una imagen de Docker que ya tenga ping instalado, por ejemplo, busybox :

docker run --rm busybox ping SERVER_NAME -c 2
 0
Author: Ivan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-13 11:18:03