Docker container terminates immediately when it did not have any foreground process that helps to connect to user terminal. For example, there is no web server up running in that container.
There are couple of ways to create a foreground process. One such method is to redirect to /dev/null which prevents container from immediate exit. After that you can use exec command with -it parameter to attach it to your terminal.
docker run -d ubuntu tail -f /dev/nulldocker exec -it 0ab99d8ab11c /bin/bash