skip to Main Content

My command is here:

sudo docker run --name ws_was_con -itd --net=host -p 8022:8022 --restart always account_some/project_some:latest cd /project_directory && daphne -b 0.0.0.0 -p 8022 project_some.asgi:application

but it returns:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "cd": executable file not found in $PATH: unknown.

I have to run with that command cd /project_directory && daphne -b 0.0.0.0 -p 8022 project_some.asgi:application without CMD on Dockerfile

How can I do that?

3

Answers


  1. You need to provide something to execute your command.

    docker run <...> account_some/project_some:latest /bin/bash cd <path>
    
    Login or Signup to reply.
  2. Try: docker run ... sh -c 'cd /project_directory; daphne -b 0.0.0.0 -p 8022 project_some.asgi:application'

    Login or Signup to reply.
  3. If you’re just trying to run a command in a non-default directory, docker run has a -w option to specify the working directory; you don’t need a cd command.

    sudo docker run -d 
      --name ws_was_con 
      -p 8022:8022 
      --restart always 
      -w /projectdirectory   # <== add this line
      account_some/project_some:latest 
      daphne -b 0.0.0.0 -p 8022 project_some.asgi:application
    

    In practice, though, it’s better to put these settings in your image’s Dockerfile, so that you don’t have to repeat them every time you run the application.

    # in the Dockerfile
    WORKDIR /projectdirectory
    EXPOSE 8022 # technically does nothing but good practice anyways
    CMD daphne -b 0.0.0.0 -p 8022 project_some.asgi:application
    
    sudo docker run -d --name ws_was_con -p 8022:8022 --restart always 
      account_some/project_some:latest
    # without the -w option or a command override
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search