I have created a docker to run PIVX coin in it. I can see the files are in the docker.
$ sudo docker exec -i ff6438b86a55 ls /usr/local/bin
pivx-cli
pivx-tx
pivxd
But when I run sudo docker exec -i ff6438b86a55 pivx-cli :
OCI runtime exec failed: exec failed: container_linux.go:344: starting
container process caused "exec: \"pivx-cli\": executable file not
found in $PATH": unknown
The docker is running and it seems the pivxd daemon is running.
$ sudo docker exec -i ff6438b86a55 ps fax
PID TTY STAT TIME COMMAND
6 ? Rs 0:00 ps fax
1 pts/0 Ss+ 0:00 tail -f /dev/null /usr/local/bin/pivxd
Make sure the executables have exec privs and Try
sudo docker exec -it ff6438b86a55 /usr/local/bin/pivx-cli
Related
I would like to send a command to an already existing docker container.
I am forced to do it via powershell or CMD, git bash not giving the correct Windows path using pwd.
Functionnal example
$cur_path = $pwd.Path
$container_id = docker run -it -d --volume $cur_path\:/matmuttools saagie/python:3.5.2-1.3.1-centos
docker exec $container_id 'ls'
docker stop $container_id
docker rm $container_id
Gives the following output:
anaconda-post.log
bin
dev
etc
git-credential-manager-2.0.4.jar
home
lib
lib64
lost+found
matmuttools
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
Non functionnal example
However, when doing something more "complex", docker throws an error:
$cur_path = $pwd.Path
$container_id = docker run -it -d --volume $cur_path\:/matmuttools saagie/python:3.5.2-1.3.1-centos
docker exec $container_id 'ls /matmuttools'
docker stop $container_id
docker rm $container_id
Throws the following error:
OCI runtime exec failed: exec failed: container_linux.go:367: starting
container process caused: exec: "ls /matmuttools": stat ls
/matmuttools: no such file or directory: unknown
If I pass ls without quotes and without more argument (just ls), it runs in the container. If I pass ls without quotes and with arguments, it runs on the host.
Runs in the container:
docker exec $container_id ls
Runs on the host:
docker exec $container_id ls /
How do I properly send a command to execute to a docker container in powershell (or with CMD) ?
In git bash, to get the actual windows path, use:
pwd -W
Now that I do not need powershell anymore (I am pretty sure it was not a blocking thing, but anyway):
docker exec -it frosty_lamport bash -c "cd /matmuttools; ls"
I am launching a container to issue some command on the host machine files.
This is done via a shell script:
echo "--- Starting container"
container_id=$(docker run -d -it --mount type=bind,source="$mount_path",target=/usr/share --name project-test python:3.5.2-alpine)
docker exec $container_id /bin/sh -c "cd /usr/share && pwd && ls -l"
However this throws an error that I do not understand how to fix:
OCI runtime exec failed: exec failed: container_linux.go:367: starting
container process caused: exec: "C:/Program Files/Git/usr/bin/sh":
stat C:/Program Files/Git/usr/bin/sh: no such file or directory:
unknown
My host machine is a windows 10. From my little understanding, the exec command on the container should opperate inside the container. But the error shows path from my host machine. Why is that ? How to properly send a command to a docker container ?
Edit:
The logs of the container after the docker exec are:
Python 3.5.2 (default, Dec 27 2016, 21:33:11)
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Edit: result of the command issued manually (expected result)
/ # cd /usr/share && pwd && ls -l
/usr/share
total 5
-rwxr-xr-x 1 root root 347 May 20 06:31 README.md
drwxrwxrwx 1 root root 4096 May 20 08:22 myproject
docker exec $container_id ls -l /usr/share
ls: C:/Program Files/Git/usr/share: No such file or directory
Your acquisition of container_id is maybe wrong. Ensure the value is correctly set in this variable before continuing.
Just a note before: you're using -d and -it options simultaneously. The -it is ignored since you tell the container to run as a daemon, you won't attach your TTY to it. The -it options are totally ignored here.
When you exec into a container, it runs a new session in the container. It means you won't see the result of the command you give in the logs since it's in the output of the new session.
To get access to the logs, you must use -it options when using exec. If you refer to #nish8690 on the question Docker exec in docker windows, you'll need to double your slashes in the command:
instead of
docker exec -it [containerid] /bin/sh
try to use
docker exec -it [containerid] //bin//sh
-- #nish8690, Docker exec in docker windows
Resulting maybe in:
docker exec -it $container_id //bin//sh -c "cd /usr/share && pwd && ls -l"
While using docker from a Windows host, the slash is converted to windows slash so the git is confusing.
To access a docker machine from a Windows host, you most to override the windows slash format by using double slash instead.
an example how to run a file, instead of running /run.sh you need to run //run.sh.
This solution will solve your problem.
I run docker exec -it 375babe4d6fc --user root /bin/bash and I get error message as follows:
OCI runtime exec failed: exec failed: container_linux.go:346: starting container process caused "exec: \"--user\": executable file not found in $PATH": unknown
But I am sure I have succeeded to run this command before.But Now I can only run docker exec -it 375babe4d6fc /bin/bash to enter the docker container.
Anybody help? Thank you
My docker's version is 2.1.0.5 on windows
I found the problem. It will be OK to use docker exec -it --user root 375babe4d6fc root /bin/bash
I installed Oracle Database in a Docker container, but can't figure out how to become root. If I to this from the host
sudo docker exec -it -u 0 oracle18se /bin/bash
or
sudo docker exec -it --user root oracle18se /bin/bash
I get
OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "chdir to cwd (\"/home/oracle\") set in config.json failed: permission denied": unknown
If I do
sudo docker exec -it oracle18se /bin/bash
from the host, and then
su -
from the container, it asks the root password, but I do not know it.
Hy host OS is Ubuntu 18.04, link to docker file
EDIT1:
Found a Docker bug.
You can exec into an existing container
docker exec -u root -it <container-id> /bin/bash
Output (as seen in Terminal):
root#<container-id>:/#
And to set root password use this:
Type the following command to become root user and issue passwd:
sudo -i
passwd
OR set a password for root user in a single go:
sudo passwd root
Test it your root password by typing the following command:
su -
You can connect as root in docker container using:
docker exec -u 0 -it <container_id> /bin/bash
The workaround is
sudo docker exec -u 0 -it --workdir / oracle12se /bin/bash
I am running the container hypriot/rpi-busybox-httpd
I am trying to ssh to docker container: but it is giving error :
pi#raspberrypi:~ $ docker exec -it cc55da85b915 bash
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"bash\": executable file not found in $PATH"
pi#raspberrypi:~ $ docker exec -it cc55da85b915 sh
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"sh\": executable file not found in $PATH"
am I doing the right away ?
It could be your image does not have the binary /bin/bash installed (as suggested before), I had the same problem and I was able to enter into the container using /bin/sh
docker exec -ti cc55da85b915 /bin/sh
Another workaround could be execute directly the commands without get access to any shell.
docker exec -ti cc55da85b915 ls /etc
The image you're using seems that it doesn't have the binary /bin/bash installed but it should have /bin/sh
Try:
docker exec -it cc55da85b915 sh
You might need to specify the full path to bash, e.g.:
docker exec -it cc55da85b915 /bin/bash
or /usr/local/bin/bash, or wherever bash is located in that image.
Hope this helps!
You have many different ways to do that, you can attach using docker's attach command.
$ sudo docker attach cc55da85b915 #by ID
Or you can use docker exec command:
$ sudo docker exec -i -t cc55da85b915 /bin/bash
If /bin/bash fails, you can use /bin/sh that works in more containers:
$ sudo docker exec -i -t cc55da85b915 /bin/sh
if you are still looking for an answer. This worked for me on windows.
winpty docker exec -it <containerid> sh
For Alpine based image, docker exec -ti cc55da85b915 /bin/sh and docker exec -ti cc55da85b915 ls /etc worked. As suggested by 'Esteban Collado'.
However for other Linux versions I use,
docker exec -ti cc55da85b915 bash
Try Below Command:
docker exec -it cc55da85b915 /bin/busybox sh
To list all the available commands use:
docker exec -it cc55da85b915 /bin/busybox --list
This will also relevant for Kubernetes pods.
For example if you'll try to connect to a pod which doesn't contain the shell you specified:
kubectl exec -it some-busybox-pod bash
(busybox have sh on it not bash).
You'll end up with the same error:
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown
command terminated with exit code 126