A polynomial whose Galois group is $D_8$ I need to construct such a polynomial, and more generally: given a group $G$, how can it be realized as a Galois group?

If you are interested in realization over $\mathbb{Q}$, then the book Inverse Galois Theory of Malle and Matzat tells us that $f=x^8-3x^5-x^4+3x^3+1$ has Galois group $D_8$ over $\mathbb{Q}$. In the end of this book there's a table of polynomials for all transitive groups up to degree $12$ over $\mathbb{Q}$. The body of the book explains in details the method to achieve realizations, and covers other topics in the area. 
