Docker, \"ping\": executable file not found in $PATH": unknown

First enter the bash in the container # 1

docker container exec -it CONTAINER bash

In bash, type

apt update

then,

apt install iputils-ping

then,

exit

then type the ping command and it should work fine

e.g. docker container exec -it new_pizd ping new_nginx2


The output

OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"ping\": executable file not found in $PATH": unknown

means that the ping command was not found (either $PATH is misconfigured, or ping is not available, or something else).

How can I check the docker variable $PATH?

Run $ docker exec -ti <CONTAINER> echo $PATH, it should output something like the following

Edit: should be $ docker exec -ti <CONTAINER> bash -c 'echo "$PATH"'

/home/user/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

$PATH is an environment variable set in *nix shells, it contains the directories where executables are looked up.

Which executable file does it refer to?

As it says in the error output, the ping executable. Once you know the content of $PATH, you can check what the problem is (ping should be in /bin, at least on the containers I have here atm), and try to solve it.

To open an interactive console to inspect/work on the container, run $ docker exec -ti <CONTAINER> bash.


Update

I have checked the bin,there is no ping inside

You probably have to install iputils-ping, see the answers here, but basically (assuming your container is based on Debian or Ubuntu or similar distribution) run

$ apt-get update
$ apt-get install iputils-ping

Tags:

Docker