If the container is running bash with PID 1
docker ps docker attach container_id
Exiting the shell will terminate the container. To exit the container without terminating it, use Control+P+Q.
Otherwise, get the container ID
docker inspect container_id | grep Pid
nsenter -m -u -n -p -i -t Pid /bin/bash
In this case, exiting the shell will not terminate the container.
The other, (preferred way, they say) is to use docker exec to run a process in a container.
docker exec -it container_id /bin/bash man docker-exec
In this method too, exiting the shell will not terminate the container.