skip to Main Content

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


  1. It might be a missing $PATH problem — does the following work?

    command:
      - /bin/ls -la /home
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search