22

When i run the below command

$ docker container exec -it nginx1 ping nginx2 

This is the error which i faced :

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

How to resolve this issue ?

hong4rc
  • 3,999
  • 4
  • 21
  • 40
Jakka rohith
  • 475
  • 2
  • 7
  • 15
  • 4
    Install `ping` into the `nginx1` image during build? – Danila Kiver Mar 27 '19 at 13:41
  • I didn't install during the build but what i did is after running the container as it was saying exec: \"ping\": executable file not found in $PATH": unknown i installed ping inside the container but was of no use \ – Jakka rohith Apr 29 '19 at 12:25
  • How *exactly* did you do this, and how you tried to verify the installation? If the binary *is* installed in the running container and *is* in PATH, it shoud work. – Danila Kiver Apr 29 '19 at 12:31
  • Firstly i entered the container using docker exec -it bash container_id and installed package manager then i installed ping the installation was successfull then after i tried this command once again ``` docker container exec -it nginx1 ping nginx2 ``` – Jakka rohith Apr 29 '19 at 12:41
  • Did you try invoking `ping` directly after installing it (not leaving the shell)? If yes did you try it by specifying the full path to the binary (e.g. /usr/bin/ping)? – Danila Kiver Apr 29 '19 at 12:43
  • `docker exec -it bash container_id` - maybe `docker exec -it container_id bash`? Command goes after container ID. – Danila Kiver Apr 29 '19 at 12:44
  • You should install ```apt-get install inetutils-ping``` inside your container. – Dipanshu Chaubey Jun 21 '19 at 17:57

8 Answers8

43

Before reading this answer just let you know, it's my 2nd day of learning docker, It may not be the perfect help for you.

This error may also occur when the ping package is not installed in the container, I resolved the problem as follow, bash into the container like this

docker container exec -it my_nginx /bin/bash

then install ping package

apt-get update
apt-get install inetutils-ping

This solved my problem.

vaibhav mehta
  • 556
  • 5
  • 7
  • I even specified `nginx:latest` when creating new containers but it definitely needs inetutils-ping package for both containers. Oh, I'd just realized it has to be `nginx:alpine` image and the ping installation is not necessary. – Thanapooom Ptjrk Jun 10 '22 at 03:17
7

Please use alpine image of nginx:

docker container run -d --name my_nginx_name nginx:alpine

docker container run -d --name my_nginx_name2 nginx:alpine

Then try to ping using below command:

docker container exec -it my_nginx_name ping my_nginx_name2

T. Short
  • 3,481
  • 14
  • 30
Ankitsrivasta
  • 73
  • 1
  • 6
5

I had the same problem and managed to solve it by accessing:

docker exec -ti <CONTAINER ID> /bin/sh
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
ukaliko
  • 172
  • 2
  • 7
  • It's not an answer to question. Also, not all containers does have `/bin/sh`, so your solution not so general. – Yasen Apr 20 '20 at 19:57
  • @Yasen `/bin/sh` usually points to the shell the containers is running [see this answer](https://stackoverflow.com/a/5725402/2445763) – lasec0203 Jul 28 '22 at 02:56
3

This something I came across recently. When ran a docker container with a custom name and if we put an command/option(s)/etc after the name, that would be passed to the container as commands. So in here container tried to find the ping command inside it but couldn't, So as the above answer you must install the inetutils-ping inside the container and run the command

Govinda Malavipathirana
  • 1,095
  • 2
  • 11
  • 29
3

Try this it worked for me

# $ docker container exec -it new_nginx bash 
# apt-get update
# apt-get install inetutils-ping

Do it for both the container than run your command

# $ docker container exec -it nginx1 ping nginx2 

    
Hiren Gohel
  • 4,942
  • 6
  • 29
  • 48
3

Install ping utilities in the container .

docker container exec -it webhost /bin/bash
apt-get update
apt-get install inetutils-ping

docker container exec -it webhost ping new_nginx
Ankit Sangwan
  • 1,138
  • 1
  • 7
  • 20
Ashu
  • 53
  • 4
  • Very nice answer, but I get error: `E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)` How do I become superuser insie docker container ? Creds ? – Sold Out Oct 05 '22 at 18:41
  • In order to be a root inside the docker container, break into it like this: `docker exec -u 0 -it containerName bash` i.e. with user 0 (-u 0) specification. – Sold Out Oct 05 '22 at 18:47
1

Try to install ping in both conatiners,

apt-get update,

apt-get install inetutils-ping

After that Try the ping command.

0

This error is reported when you try to run the command not found in docker image. Please check if ping is installed in the docker image.

Akash Sharma
  • 721
  • 3
  • 6