Reputation: 1
Attempting to run command
fails from docker exec, but not from an interactive shell.
Shell
# command which echo
/usr/bin/echo
# which echo
/usr/bin/echo
#
docker exec
C:\dev> docker ps -n 1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93eb09dcde3b ubuntu "/bin/bash" 4 minutes ago Up 4 minutes peaceful_knuth
C:\dev> docker exec peaceful_knuth command which echo
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"command\": executable file not found in $PATH": unknown
C:\dev> docker exec peaceful_knuth which echo
/usr/bin/echo
C:\dev>
Upvotes: 0
Views: 2337
Reputation: 1
I figured it out not seven seconds after posting. Today's lesson: RTFM.
From https://docs.docker.com/engine/reference/commandline/exec/
docker exec -ti my_container sh -c "echo a && echo b"
The result
C:\dev> docker exec peaceful_knuth command which echo
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process
caused "exec: \"command\": executable file not found in $PATH": unknown
C:\dev> docker exec peaceful_knuth which echo
/usr/bin/echo
C:\dev> docker exec peaceful_knuth sh -c "command which echo"
/usr/bin/echo
C:\dev>
From https://stackoverflow.com/users/9072753/kamilcuk, upvote his answer.
C:\dev> docker exec peaceful_knuth type command
OCI runtime exec failed: exec failed: container_linux.go:349: starting container
process caused "exec: \"type\": executable file not found in $PATH": unknown
C:\dev> docker exec peaceful_knuth sh -c "type command"
command is a shell builtin
C:\dev>
Upvotes: 0
Reputation: 141708
$ type command
command is a shell builtin
command
is a shell builtin. There is no /usr/bin/command
. To run a shell builtin, first run the shell.
docker ...... sh -c 'command which echo'
Upvotes: 1