23

I have these two containers on the same network

docker inspect my_app_net
[
    {
        "Name": "my_app_net",
        "Id": "e136b758e8009e0361168aa0ead14ec85973c8d4f93e65122c22a2ff18f5e61f",
        "Created": "2018-03-22T21:11:51.781623693+01:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.19.0.0/16",
                    "Gateway": "172.19.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "a966584cd491caff18b25fa347b738a0853e5195ac517b5fb26bb019a271fc10": {
                "Name": "new_pizd",
                "EndpointID": "fdbacbbd564aeacccc57367dd082232e0498976ca485597b6ba8f6c82a0d4240",
                "MacAddress": "02:42:ac:13:00:03",
                "IPv4Address": "172.19.0.3/16",
                "IPv6Address": ""
            },
            "b36f350efca1f2e79bef8027a32f992021091fdd701e4d55d98af78984072150": {
                "Name": "new_nginx2",
                "EndpointID": "38731d2618aba0a7c63debd3b30a4c9b530d83a4fddbda97cdd2498298007120",
                "MacAddress": "02:42:ac:13:00:02",
                "IPv4Address": "172.19.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

When I try to ping the second from the first

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

This is quite strange. How can I check the docker variable $PATH? Which executable file does it refer to? EDIT

Suggested answer asks for echo PATH,but it is the same as from my Ubuntu shell

docker exec -ti new_nginx2 echo $PATH
/home/milenko/eclipse:/home/milenko/miniconda3/bin:/home/milenko/bin:/home/milenko/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

And

milenko@milenko-System-Product-Name:~$ docker exec -ti new_nginx2 bash
root@b36f350efca1:/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

I have checked the bin,there is no ping inside

root@b36f350efca1:/bin# ls ping*
ls: cannot access 'ping*': No such file or directory
MikiBelavista
  • 2,470
  • 10
  • 48
  • 70
  • I updated my answer, can you check if this was it? – resc Mar 24 '18 at 11:31
  • 1
    Using alpine would be the best solution instead of installing it. Tribid_bose answer works great. In fact Bret also tells the same thing. – Eswar Jan 31 '20 at 11:10

5 Answers5

35

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
resc
  • 541
  • 6
  • 11
  • 1
    Yeah sorry, it should really be `docker exec -ti bash -c 'echo "$PATH"'`, otherwise your shell expands `$PATH`. I'll correct my answer. – resc Mar 24 '18 at 11:22
27

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

Rhonald
  • 363
  • 5
  • 18
  • If you want to perform ping from both the containers to each other, you need to install ping on both the containers as well. – Rhonald Jan 30 '19 at 04:15
  • If you want to ping one container from the other container then both of them should be on the same network created by you. It does not work in the default network. – Kishan Vaishnav Apr 08 '21 at 08:31
6

Step -1

docker container exec -it mynginx ping newnginx

if above step giving error

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

Step -2

docker container exec -it mynginx bash

Step-3

apt-get update

Step-4

apt-get install iputils-ping

Step -4

Exit()

Step-5

docker container exec -it mynginx ping newnginx

it will ping .

Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
jayesh
  • 3,277
  • 1
  • 18
  • 7
6

May be your container is not having ping. login to that container using docker exec -it <Container_Name> bash this will open the bash inside your container. then type below commands. apt-get update;apt-get install iputils-ping;

praveen d
  • 65
  • 1
  • 2
3

Instead of using nginx in docker container run command as nginx image doesn't have ping command, use nginx:alpine. nginx:alpine image has ping command associated with it. Example follows

docker container run --name new_nginx2 -d --network my_app_net nginx:alpine
TRIDIB BOSE
  • 391
  • 3
  • 3