Run a command in a container with no shell?

The description of how commands works says that it converts them into a script run in /bin/sh. What about if the container image does not have /bin/sh in it? FROM scratch images are becoming pretty popular.

Actually, plugins/base appears not have have /bin/sh either:

$docker run --rm plugins/base:multiarch sh
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"sh\": executable file not found in $PATH": unknown.

The shell is only required when you have a commands section. You will not that plugins never have a commands section, hence why a shell is not required. Instead they use entrypoint and command which you can set directly in the yaml in lieu of commands if you prefer.

- name: foo
  image: bar
  entrypoint: [ /path/to/command ]
  command: [ "--one", "--two" ]

Ah, you can use entrypoint like k8s? I didn’t know. I tried to find the docs for the full config, but couldn’t find them.

So if I do the syntax above, it will run it without a shell?


It is documented in the services section since this is where it is mostly used. This is the first time someone has asked me about using entrypoint and command in a pipeline step :slight_smile:

So if I do the syntax above, it will run it without a shell?

yes, here is a working example:

kind: pipeline
name: default
- name: foo
  image: alpine:3.8
  entrypoint: [ /bin/echo ]
  command: [ hello, world ]

Thanks Brad. There is a bug in one of the plugins in how it calls a command (already opened an issue, and a PR), but the plugin doesn’t have sh, so I thought I would keep the same one, just execute around it. Didn’t work as it required /bin/sh. Now I know how to work around it.

In the end, just took a different image and ran some installs. Suboptimal, but works.