A magnetic field exists around all wires carrying a current.
When there is no current the compass needles in the diagram line up with the Earth's magnetic field. A current through the wire produces a circular magnetic field.
The magnetic field for a coil of wire is shown below. The magnetic fields from each of the turns in the coil add together, so the total magnetic field is much stronger. This produces a field which is similar to that of a bar magnet. A coil of wire like this is often called a solenoid.