docker run -d ubuntu bash
Container will immediately exit. What I need is keeping the container run, and I can use exec
to login into this container.
In fact, I need do these things in a bash script:
docker run -it ubuntu bash
docker run -it centos bash
But it does not work.
Another option is to use -i
and -d
together (I expected them to be mutually exclusive and was surprised to learn they are not).
See example output below, I started an Ubuntu container with -itd
flags, then waited a couple of minutes and ran docker ps
to confirm that the container is still running.
> docker run -itd ubuntu
03c55e9ba9de3e0b80ad9f3e0629dc63f4ab65291b79e133af2b392030ffc17d
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
03c55e9ba9de ubuntu "/bin/bash" 2 minutes ago Up 2 minutes gallant_hypatia
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With