194

I have dockerized an app which has ffmpeg installed in it via libav-tools. The app launches without problem, yet the problem occured when fluent-ffmpeg npm module tried to execute ffmpeg command, which was not found. When I wanted to check the version of the ffmpeg and the linux distro set up in the image, I used sudo docker exec -it c44f29d30753 "lsb_release -a" command, but it gave the following error: OCI runtime exec failed: exec failed: container_linux.go:296: starting container process caused "exec: \"lsb_release -a\": executable file not found in $PATH": unknown

Then I realized that it gives me the same error with all the commands that I try to run inside the image or the container.

OCI runtime exec failed: exec failed: container_linux.go:296: starting container process caused "exec: \"ffmpeg -a\": executable file not found in $PATH": unknown

This is my Dockerfile:

FROM ubuntu:xenial
FROM node
RUN apt-get -y update
RUN apt-get --yes install libav-tools
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
RUN npm run build
ENV NODE_ENV production
EXPOSE 8000
CMD ["npm", "run", "start:prod"]

I would kindly ask for your help. Thank you very much!

Uğur Kaya
  • 2,287
  • 3
  • 15
  • 23
  • 7
    try entering your container with `docker run --rm -ti your-image-name sh` and find your executable. It is probably only a PATH problem (the directory where your executable is placed in is not in the PATH of the root unser inside the container) – whites11 Dec 28 '17 at 09:52
  • I have entered the container with the command that you recommended. The problem is that when I try to do `apt-get install ffmpeg`, the outcome is:`Package ffmpeg is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'ffmpeg' has no installation candidate`. However I can get the same package in my ubuntu 16.04 OS. May something be wrong with the OS in the container? – Uğur Kaya Dec 28 '17 at 13:53
  • did you run `apt-get update`? – whites11 Dec 28 '17 at 13:55
  • I did run `apt-get -y update && apt-get -y upgrade`, and inside the container when I try to run `lsb_release -a`, this time the output is `sh: 4: lsb_release: not found`, same for ffmpeg: `sh: 5: ffmpeg: not found`. I run `apt-get install libav-tools` and get `# apt-get install libav-tools Reading package lists... Done Building dependency tree Reading state information... Done libav-tools is already the newest version.`. If I `find -name "ffmpeg"` output is empty. – Uğur Kaya Dec 28 '17 at 14:24
  • @whites11 I believe you are right, it seems to be a PATH problem, because inside the container, whatever I `apt-get install` and `apt-get update`, it is installed in container, yet after all I cannot run the command. Same happened for `apt-get install lsb-release`, it has installed and still couldn't run the command after installation: `sh: 3: lsb-release: not found`. Could you please give me a little bit more detailed information about how I can solve PATH problem? – Uğur Kaya Dec 28 '17 at 14:32
  • 1
    First of all you have to find the absolute path of your executable (using find, maybe). Then, you have 2 options: 1) use the full path of the executable in your docker's CMD (and in general everywhere you are calling an executable) 2) add the directory that contains your binary to the end of the PATH environment variable, such as: `export PATH=$PATH:/my/bin/folder` – whites11 Dec 28 '17 at 14:36
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/162106/discussion-between-ugur-kaya-and-whites11). – Uğur Kaya Dec 28 '17 at 15:29
  • See also https://stackoverflow.com/q/27158840/798677 – That Brazilian Guy Apr 08 '19 at 15:34
  • Get some more solution [over here](https://serverfault.com/questions/1050868/kubernetes-oci-runtime-exec-failed-starting-container-process-caused-exec/1084774#1084774) – MD SHAYON Nov 28 '21 at 10:58
  • Try this docker exec -ti sh -c – O Wigley Mar 04 '22 at 12:43
  • `winpty docker exec -it //bin//sh` (if you're using Git Bash in Windows) – Tiago Martins Peres Mar 22 '23 at 12:45

16 Answers16

237

This happened to me on windows. See below for any of the commands that match your case.

NOTE

You will need to run the commands that match your case below using the correct shell in your container i.e. /bin/bash or /bin/sh. Using sh instead of bash or vice versa will also give you this error. So, confirm that you are using the right shell, or just try both shells and see the one that works. For these examples, I will be using sh

On Windows CMD (not switching to bash):

docker exec -it <container-id> /bin/sh

On Windows CMD (after switching to bash):

docker exec -it <container-id> //bin//sh

or

winpty docker exec -it <container-id> //bin//sh

On Git Bash:

winpty docker exec -it <container-id> //bin//sh

For Windows users, the reason is documented in the ReleaseNotes file of Git and it is well explained here - Bash in Git for Windows: Weirdness... :

The cause is to do with trying to ensure that posix paths end up being passed to the git utilities properly. For this reason, Git for Windows includes a modified MSYS layer that affects command arguments.

Linux

docker exec -it <container-id> /bin/sh

papigee
  • 6,401
  • 3
  • 29
  • 31
74
docker exec -it <containerId> sh
Bijaya Kumar Oli
  • 2,007
  • 19
  • 15
  • 3
    OCI runtime exec failed: exec failed: unable to start container process: exec: "sh": executable file not found in $PATH: unknown – pszaba Jun 25 '22 at 15:52
  • 1
    This did the trick for me on Amazon Linux 2 on my EC2 – Amon Nov 30 '22 at 14:28
41

I had this due to a simple ordering mistake on my end. I called

[WRONG] docker run <image> <arguments> <command>

When I should have used

docker run <arguments> <image> <command>

Same resolution on similar question: https://stackoverflow.com/a/50762266/6278

Henrik Heimbuerger
  • 9,924
  • 6
  • 56
  • 69
  • 1
    what if I'm using docker-compose what could be the mistake? I ran using `docker-compose -f .\a-docker-compose-file.yml up` – otong Jan 15 '19 at 03:39
  • 2
    @otong Your comment has nothing to do with my answer. Please post it as a new question and give more detail to your specific problem there. – Henrik Heimbuerger Jan 15 '19 at 07:26
  • 2
    This *does* apply also to docker compose and fixed it for me. Thank you very much – David Oct 04 '19 at 14:09
25

Get rid of your quotes around your command. When you quote it, docker tries to run the full string "lsb_release -a" as a command, which doesn't exist. Instead, you want to run the command lsb_release with an argument -a, and no quotes.

sudo docker exec -it c44f29d30753 lsb_release -a

Note, everything after the container name is the command and arguments to run inside the container, docker will not process any of that as options to the docker command.


For others with this error, the debugging steps I'd recommend:

  • Verify the order of your arguments. Everything after the container name/id is a command to run. So you don't want docker exec $cid -it /bin/sh because that will try to run the command -it in the $cid container. Instead you want docker exec -it $cid /bin/sh

  • Look at the command that is failing, everything in the quotes after the exec error (e.g. lsb_release -a in "exec: \"lsb_release -a\") is the binary trying to be run. Make sure that binary exists in your image. E.g. if you are using alpine or busybox, bash may not exist, but /bin/sh does. And that binary is the full string, e.g. you would be able to run something like ls "/usr/bin/lsb_release -a" and see a file with the space and -a in the filename.

  • If you're using Windows with Git bash and see a long path prefixed on that command trying to be run, that's Git bash trying to do some automatic conversions of /path/to/binary, you can disable that by doubling the first slash, e.g. //bin/sh.

  • If the command you're running is a script in the container, check the first line of that script, containing the #!/path/to/interpreter, make sure that interpreter exists in the image, at that path, and that the script is saved with linux linefeeds (lf, not cr+lf, you won't want the \r showing in the file when read in linux because that becomes part of the command it's looking to execute).

  • If you don't have a full path to the binary in the command you're running, check the value of $PATH in the image, and verify the binary exists within one of those directories. E.g. you can docker exec -it $cid /bin/sh and echo $PATH and type some_command to verify some_command is found in your path.

  • If your command is not an executable, but rather a shell builtin, you'll need to execute it with a shell instead of directly. That can be done with docker exec -it $cid /bin/sh -c "your_shell_builtin"

BMitch
  • 231,797
  • 42
  • 475
  • 450
25

If @papigee does solution doesn't work, maybe you don't have the permissions.

I tried @papigee solution but does't work without sudo.

I did :

sudo docker exec -it <container id or name> /bin/sh
  • Yes this worked, thank you. I assumed `/bin/bash` was available in the image. It was not but `/bin/sh` was and it works good enough for what I need. – johnpitchko Jul 24 '21 at 03:19
17

I solved this with this commands:

  1. Run the container:
    docker run -d <image-name>
    
  2. List containers:
    docker ps -a
    
  3. Use the container ID:
    docker exec -it <container-id> /bin/sh
    
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Carlos Marcano
  • 610
  • 6
  • 6
6

I was running into this issue and it turned out that I needed to do this:

docker run ${image_name} bash -c "${command}"
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
LucidIguana
  • 61
  • 1
  • 1
2

You can use another shell to execute the same command:

Error I get when i execute:

[jenkins@localhost jenkins_data]$ docker exec -it mysqldb \bin\bash
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"binsh\": executable file not found in $PATH": unknown

Solution: When I execute it with below command, using bash shell it works:

[jenkins@localhost jenkins_data]$ docker exec -it mysqldb bash
root@<container-ID>:/#
mate00
  • 2,727
  • 5
  • 26
  • 34
Jagdish0886
  • 343
  • 1
  • 5
  • 20
  • I'm pretty sure your problem is that you are using backslashes in \bin\sh. Linux doesn't use those, so it is stripping them out. Use /bin/sh instead. "bash" works because there are no backslashes. – Alejandro703 Feb 18 '21 at 20:24
2

What I did to solve was simply:

  1. Run docker ps -a
  2. Check for the command of the container (mine started with /bin/sh)
  3. Run docker-compose exec < name_of_service > /bin/sh (if that is what started your command

This is for solving when using docker compose

1

I was running a container in a docker-compose.

entrypoint:
  - ls

worked, but

entrypoint:
   - ls tests

did not.

It's because the arguments have to be on separate lines.. ‍♂

entrypoint:
   - ls 
   - tests
Pickled
  • 465
  • 1
  • 4
  • 10
0

This has happened to me. My issue was caused when I didn't mount Docker file system correctly, so I configured the Disk Image Location and re-bind File sharing mount, and this now worked correctly. For reference, I use Docker Desktop in Windows.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Rand Chen
  • 101
  • 4
0

In my case i saved the docker image and instead of load-ing it on the other machine i imported it which are very different and lead me to an error similar to this.

Hooloovoo
  • 86
  • 4
0

you have to run like below:

docker exec sh -c 'echo "$ENV_NAME"'

  • 1
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Jul 25 '21 at 07:37
0

I had windows line endings in a shell script. change to LF dos2unix

Dave Horner
  • 405
  • 5
  • 10
0

If you got this error when using the docker run command, you may have made a simple syntax error.

Example

Incorrect:

docker run myimage -p 3838:3838 

docker: Error response from daemon: failed to create shim: OCI runtime create
failed: container_linux.go:380: starting container process caused: 
exec: "-p": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled 

Correct (options go before image name):

docker run -p 3838:3838 myimage
stevec
  • 41,291
  • 27
  • 223
  • 311
0

In my case, I was running like this which was the wrong way ❌

docker exec c44f29d30753 -it bash

Run like this ✅

docker exec -it c44f29d30753 bash 
Visrut
  • 360
  • 4
  • 14