It was actually written for the 1959 Broadway musical "The Sound of Music," upon which the movie is based. The song is a key part of the musical, where Maria teaches the von Trapp children about music using the solfège system.
Richard Rodgers and Oscar Hammerstein II, the musical's composers, crafted the song specifically for the Broadway production. It later became one of the most recognizable and beloved songs from the musical and film.