OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: - image

I have created image with our application, after running the image i can see the docker containers are also created, when I am trying to getinto the docker container i am getting the below error, can you please help me here.
""""OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: "bash": executable file not found in $PATH": unknown""""
I have tried to execute all the below commands
docker run -it exec 962f5d99458c
docker run -it 962f5d99458c
docker exec -it 962f5d99458c /bin
docker exec -it 75f6cb44f9e1
docker run --rm -ti 962f5d99458c sh
docker run --rm -ti 962f5d99458c /bin
docker exec --rm -ti 962f5d99458c /bin
docker exec -ti 962f5d99458c /bin
docker exec -ti 962f5d99458c \bin
docker exec -it 75f6cb44f9e1 bash
but no luck..... can you please help me here.

What the error says is that the startup command is invalid because the image has no (or it's not on $PATH) certain executable in it (bash in this case). The absence of bash is adequate for certain images (e.g. based on Alpine Linux or scratch) but if there is any shell at all, you can use sh:
# create a container from image and get straight into shell
docker run -it <image> sh
# or start a container in background, then get into shell
docker run -d <image>
docker exec -it <container> sh
If the image has no shell in it, then the only way to launch it, is by using the binary of the application the image supposed to run. Normally it works out of the box, unless you've overridden ENTRYPOINT and/or CMD in Dockerfile or by run arguments. The default startup arguments can be found with docker inspect:
docker image inspect nginx | jq '.[0].Config.Entrypoint'
docker image inspect nginx | jq '.[0].Config.Cmd'
In case you absolutely sure that the executable is there but still get the error, using an absolute path might help (e.g. /bin/bash instead of simply bash).

Related

Execute script when docker container start

I want container with "centos:latest" image to be started and should execute my script. The scripts are copied with docker cp commands.
docker create --name centos1 centos:latest
docker cp . 5db38b908880:/opt ---> scripts are in current directory, hence .
docker commit centos1 new_centos1 --> now new_centos1 image has scripts
Now I want to start new container with the scripts to be executed: I tried below commands:
docker run -ti --rm --entrypoint "cd /opt && deploy_mediainfo_lambda.sh" new_centos1:latest
docker run -ti --rm new_centos1:latest "cd /opt && deploy_mediainfo_lambda.sh"
Both of above commands failed with:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"cd /opt && deploy_mediainfo_lambda.sh\": stat cd /opt && deploy_mediainfo_lambda.sh: no such file or directory": unknown.
ERRO[0000] error waiting for container: context canceled
if used bash command while starting container, I can run my script using 'execuateble path'/'execuatble name' inside container, but I can not do this while starting container on commandline
docker run -ti --rm new_centos1:latest bash
[root#c34207f3f1c4 /]# ./opt/deploy_mediainfo_lambda.sh
If used below command, which calls executable directly, it gives path error.
docker run -ti --rm new_centos1:latest "deploy_mediainfo_lambda.sh"
docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"deploy_mediainfo_lambda.sh\": executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled
Also not sure about setting $PATH from commandline while starting the container.
I know, using Dockerfile this is achievable, like:
can set path using ENV,
can copy executables with ADD or COPY
run executables using CMD or ENTRYPOINT
How to achieves it using docker commandline?
Thanks melpomene.
Here is my bash script to automate script execution inside container, after copying them, all using docker commands.
# Start docker container
docker create --name mediainfo_docker centos:latest
# copy script files
docker cp . mediainfo_docker:/opt
# save container with the new image, which contains all scripts.
docker commit mediainfo_docker mediainfo_docker_with_scripts
# Now run scripts inside docker container
docker run -ti --rm mediainfo_docker_with_scripts:latest /opt/deploy_mediainfo_lambda.sh
Since deploy_mediainfo_lambda.sh is a script, first line of it is:
#!/bin/bash

Run command from .bashrc in detached docker container

I'm running a docker container in detached mode, and I'm having difficulty running a command that's in the container's ~/.bashrc.
Inside the docker container's ~/.bashrc:
labserve () {
jupyter lab --ip=0.0.0.0 --allow-root --no-browser --NotebookApp.token=''
}
If I start the container with
$ docker run -d image -p 8888:8888 --name jupyterbox
I'd like to be able to tell the image to tell the detached container to open up jupyterlab with the following command:
$ docker exec jupyterbox bash -c labserve
however, when I do that, I get the error
bash: labinit: command not found
On the other hand, if I do
$ docker run -it jupyterbox bash
root#4e344655fc31:/home# labserve
The command runs correctly, and opens up a jupyterlab within my docker container running on port 8888.
How do I exec this command in a detached container?

Running shell script using Docker image

Input:
- There is Windows machine with Docker Toolbox installed.
- There is a shell script file baz.sh which calls py2dsc-deb.
Problem: py2dsc-deb is not available on Windows.
As I understand correctly, I can pull some Linux distro image from Docker repository, create a container and then execute shell-script file and it will run py2dsc-deb and do its job.
I have pulled:
debian - stretch-slim - 3ad21 - 3 weeks ago - 55.3MB
Now
How do I run my script using debian, something like: docker exec mycontainer /path/to/test.sh?
Running docker --rm debian:stretch-slim does nothing. Doesn't it suppose to run Debian distro at docker-machine ip?
I have tried to keep the container up using docker run -it debian:stretch-slim /bin/bash, then run the script using docker exec 1ef5b ./build.sh, but getting
$ docker exec 745 ./build.sh
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"./build.sh\": stat ./build.sh: no such file or directory"
Does it mean I can't run external script and has to always pass it inside the Docker?
You can execute bash command inside your container by typing
docker exec -ti -u `username` `container_name` bash -c "cd /path/to/ && ./test.sh"
lets say your container name is test_buildbox, you are root and your script stays inside /bin/test.sh You can call this script by typing
docker exec -ti -u root test_buildbox bash -c "cd /bin/ && ./test.sh
Please check if you have correct line endings in your .sh scripts (<LF>) when you built Docker image on Windows.

Piping docker run container ID to docker exec

In my development, I find myself issuing a docker run command followed by a docker exec command on the resulting container ID quite frequently. It's a little annoying to have to copy/paste the container ID between commands, so I was trying to pipe the container ID into my docker exec command.
Here's my example command.
docker run -itd image | xargs -i docker exec -it {} bash
This starts the container, but then I get the following error.
the input device is not a TTY
Does anyone have any idea how to get around this?
Edit: I also forgot to mention I have an ENTRYPOINT defined and cannot override that.
Do this instead:
ID=$(docker run -itd image) && docker exec -it $ID bash
Because xargs executes it arguments without allocating a new tty.
If you just want to "bash"-into the container you do not have to pass the container-id around. You can simply run
docker run -it --rm <image> /bin/bash
For example, if we take the ubuntu base image
docker run -it --rm ubuntu /bin/bash
root#f80f83eec0d4:/#
from the documentation
-t : Allocate a pseudo-tty
-i : Keep STDIN open even if not attached
--rm : Automatically remove the container when it exits
The command /bin/bash overwrites the default command that is specified with the CMD instruction in the Dockerfile.

How can I run docker container without entering into container

I have Dockefile
FROM centos:7
So I have no entrypoint in dockerfile.
Then I build it to image
sudo docker build -t my_container .
Then I start it.
sudo docker run -t my_container
And I get open tty to container
root#my_container_id/
If I start it without -t it stopped immidiately after start.
How can I run docker container without start tty and without entrypoint?
You can start your container in a detached mode:
docker run -it -d my_container
The -d option here means your container will run in "detached" mode, in the background.
If you want to attach the container and drop to a shell, you can use:
docker exec -it my_container /bin/bash
Note, if your container is based on an alpine image, you need to use sh, i.e.:
docker exec -it my_container /bin/sh
You can't do that. Your container lives if its main process is running, so you have to have a main process which is the process with PID 1 inside your container, and your container will be up if that process is running.

Resources