Reputation: 69993
I am a newbie to Docker, and I know that one way to run an interactive container is the following:
$ docker run -it image-name bash
or
$ docker run -it image-name /bin/bash
However, if I use the following:
$ docker run -it image-name
It seems I get the same result. Can somebody explain me the difference between these commands if there is any difference.
Upvotes: 1
Views: 127
Reputation: 43798
The first two start the container and then run the program bash
respectively /bin/bash
(which in most of the cases will be the same) inside it.
The last version starts the container and then runs the program specified in the image with the CMD directive. Some images, notably the ones containing just a base OS, have also /bin/bash
or some other shell defined there. In these cases there is no difference.
But if you use an image that has another program specifed as command (for example mysql) you will note the difference.
To make things even more complicated, images can also specify an ENTRYPOINT, which again changes the behaviour. Please see the documentation for that.
Upvotes: 3