This poem appears in his book Alice's Adventures in Wonderland which was published in 1865 and is recited by Alice in chapter 5.
It is a parody of Robert Southly's didactic poem The Old Man's Comforts and How He Gained Them.