0

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 3

2

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.

command: [ "ls", "-la", "/home" ]

To run multiple commands,

command: ["/bin/bash", "-c", "ls -lah; whoami; hostname"]

But as the comments pointed out, as this increases complexity, consider running a script instead.

Sign up to request clarification or add additional context in comments.

4 Comments

You're right... Is there a way to let's say separate this commands? Suppose that I would like to call two commands, first: chmod +x /home/my-exe and then /home/my_exe --opt. When I put all this "parts" of my command in the array, then it says: chmod: unrecognized option --opt
@bielu000, if you want a command that can run multiple other commands, that's what shells are for.
You could also RUN chmod ... in your Dockerfile, so that you don't need to repeat that setup step every time you run a new container.
@bielu000you could wrap it in a bash. command: ["/bin/bash", "-c", "ls -lah; whoami; hostname"] but the other comment is right, if you're venturing into multiple commands, consider running a script.
1

There is no command "ls -la /home". There is command ls that takes -la argument and /home argument.

command:
  - ls
  - "-la"
  - /home

Or alternatively, docker-compose will do the splitting if you pass a string instead of an array (consult YAML specification):

command: "ls -la /home"

Or just:

command: ls -la /home

Comments

-1

It might be a missing $PATH problem -- does the following work?

command:
  - /bin/ls -la /home

1 Comment

This is trying to run an executable named home in a directory named ls -la (plus a space on the end) that is itself a subdirectory of /bin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.