I’m trying to use docker compose to run my services. But for some reason I’m not able to call e.g. this command ‘ls -la /home’. It gives me an error:
Cannot start service test: failed to create shim task: OCI runtime create failed: runc >create failed: unable to start container process: exec: "ls /home": stat ls /home: no such >file or directory: unknown
whereas when I use just ‘ls’ then I see all the directories… what’s wrong?
Below is my docker-compose file:
version: "3"
services:
mqtt_broker:
build:
dockerfile: Dockerfile
context: ./
network_mode: host
test:
depends_on: [ mqtt_broker ]
image: ubuntu:22.04
command:
- ls -la /home
network_mode: host
3
Answers
It might be a missing $PATH problem — does the following work?
There is no command
"ls -la /home"
. There is commandls
that takes-la
argument and/home
argument.Or alternatively, docker-compose will do the splitting if you pass a string instead of an array (consult YAML specification):
Or just:
Enclose your command with the array notation (just like in Dockerfiles), so that it is properly joined together as one, instead of different parts being interpreted separately.
To run multiple commands,
But as the comments pointed out, as this increases complexity, consider running a script instead.