3

According to here, in order to docker-run multiple commands, I need

docker run image_name /bin/bash -c "cd /path/to/somewhere; python a.py"

However, I can specify the default shell in the Dockerfile with the SHELL instruction. So given that I can already specify the default shell of a container, why is it necessary to specify again with /bin/bash -c when running the docker container? What was the rationale behind not automatically using the shell specified with the SHELL instruction?

oguz ismail
  • 1
  • 16
  • 47
  • 69
Rufus
  • 5,111
  • 4
  • 28
  • 45

1 Answers1

1

the SHELL instruction in the Dockerfile is only used for the Dockerfile RUN instructions (done during image creation)

docker run is a completely different command (it creates a container and run a command in it). The command you specify after the image name depends on the way the image is built. Some containers allow to run arbitrary command and also /bin/bash (if installed).

The default command is specify within you docker file with the Dockerfile CMD instruction. It default to empty.

You can also specify an ENTRYPOINT instruction that will run the CMD. The default is /bin/sh.

Cyrille Pontvieux
  • 2,356
  • 1
  • 21
  • 29
  • This shell will active not only during building, but also in image too: https://github.com/moby/moby/issues/7281#issuecomment-389440503 – Eugen Konkov Jun 19 '22 at 14:18