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?
 A: For the case that $D_8$ is interpreted to be with $16$ elements (which is the case according to OP on M.SE) an example is given by 
$$ x^8 - 3 x^5 - x^4 + 3x^3 +1 $$
This is a polynomial with minimal (in absolute value) discriminant with that Galois group.
For the other interpretation of $D_8$ a polynomial with minimal discriminat would be 
$$x^4 - x^3 -x^2 +x +1 $$
As said in the comments the general problem is difficult (indeed open even regarding existence, that is over the rationals, which I assume is the intention of the question). 
The above polynomials and information are taken from the database of Jürgen Klüners and Gunter Malle 
where a great many examples and information can be found, presented in a nice way. 
So, for examples for specific not too large groups one migt well find a polynomial there, even if one wishes additional restrictions (on the siganture, say).
A: For Galois groups up through degree eight, you can easily provide an infinte number of examples by the function field extensions listed here:
Some polynomials over Q(t) and their Galois groups
A: Over $\Bbb Q$, F. Seidelmann, in
"Die Gesamtheit der kubischen und biquadratischen Gleichungen mit Affekt bei beliebigen Rationalitätsbereich, 
Math. Ann. 78, 230--233 (1917)",
gives the following parametric representation of degree $4$ equations with group $D_8$:
$$x^4-2(e^2f+g)x^2-4efx+[(e^2f-g)^2-f]=0$$
(with some restrictions on the parameters)
