Turn off the electricity and see what happens to the compass direction.
This was the basis of Hans Cristian Oersted the Danish physicist's experiment that demonstrated the relationship between magnetism and electricity.
Oersted then realized that a coil of wire carryng a current would produce a magnetic field with the poles at the end.
A solenoid is a long coil of wire with many loops. The magnetic field of a solenoid can be greatly increased by increasing the number of coils of wirwe or the amount of current flowing through the coils. An even greater increase in the magnetic field occurs if the coil is wrapped around a piece of iron.