The best way to attach to the container through exec command.
Attach to docker running container
docker exec -it YOUR_CONTAINER_ID bash
Attach to Kubernetes running container.
kubectl exec -it YOUR_CONTAINER/POD_NAME bash
Attach to Kubernetes running container in a given namespace.
kubectl exec -it YOUR_CONTAINER/POD_NAME -n YOUR_NAMESPACE bash