Home > Software engineering >  Is there any way to run docker with multiple command?
Is there any way to run docker with multiple command?

Time:12-24

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?

CodePudding user response:

Try: docker run ... sh -c 'cd /project_directory; daphne -b 0.0.0.0 -p 8022 project_some.asgi:application'

CodePudding user response:

You need to provide something to execute your command.

docker run <...> account_some/project_some:latest /bin/bash cd <path>

CodePudding user response:

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
  • Related