Ireland is not quite the same standard as the rest of Europe when it comes to train and public transportation. Your plan to train to Sligo and then rent a car, dropping it in Galway and then training back to Dublin will be best. You are correct that you do not want a car in Dublin.
Check the train schedules from my Transport page to see what is available to you.