Immigrants worked on railroads in the time after the Civil War for much the same reasons that immigrants have the sorts of jobs that they do now. Immigrants typically get the jobs that native-born Americans do not want. These are jobs that are dangerous, unpleasant, low-paying, or some combination of the three. Railroad jobs were typically dangerous and low-paying. Many Chinese, for example, were killed while building the transcontinental railroad in California. As can be seen in the link below, railroad owners said they could not find enough willing American workers and so they hired Chinese who were willing to do the work.
Anti-immigrant feeling arose largely for the same reasons that it arises today. One problem was that Americans felt that the immigrants were too different and that they did not want to become American. This was particularly true of Chinese immigrants but native-born Americans also felt that immigrants from places like Ireland were too different to be good Americans. Another problem was that Americans felt that immigrants were hurting them economically. Then, as now, there was concern that immigrants were coming to the United States and taking jobs away from native-born Americans.
Thus, many aspects of the immigrant experience in the middle- and late-1800s were similar to the way things are today.