Have you ran d/boot_dev --init first? If so, then d/rails, d/rake, etc should work fine.
Of course you can manage/interact with the container directly yourself, but I’d say the helper scripts are … helpful? I hack on Discourse locally with the Docker setup, and the helper scripts are all I need so far.
EDIT: just realized your question was regarding using docker exec specifically, in that case, I recommand checking out the official reference (or the helper scripts themselves) and then you will see the necessary syntax to interact with an existing container.