Athens Airport has a station, you can see it in the map below. The blue and red walking routes converge at the station.
The blue walking route leads from arrival point B and the red from arrival point A. You can buy rail tickets in the airport station

Two different rail services run from Athens Airport to Piraeus. The first is the Athens Metro, the second is the Proastiakos ‘Suburban’ railway. We have marked the Metro route in green and the Proastiakos route in Yellow.
The Metro is the one you would need
The Metro is available between 06:30 in the morning till 23:30 in the evening. It leaves from Athens Airport metro station every 30 minutes. You need to change at Monastiraki
Departure times:
06:33, 07:03, 07:33, 08:03, 08:33, 09:03, 09:33, 10:03, 10:33, 11:03,
11:33, 12:03, 12:33, 13:03, 13:33, 14:03, 14:33, 15:03, 15:33, 16:03,
16:33, 17:03, 17:33, 18:03, 18:33, 19:03, 19:33, 20:03, 20:33, 21:03, 21:33, 22:03, 22:33, 23:03, 23:33
The trip from Athens Airport to Monastiraki takes 40 minutes. From Monastiraki to Pireaus port it is another 30 mins.
There are different types of tickets
Ticket for one person (one - way): 10 Euro
Ticket for one person (with return): 14 Euro
Ticket for 2 persons (one - way only): 18 Euro
Ticket for 3 persons (one - way only): 24 Euro
Reduced ticket (students age 25-, age 6 -18, age 65+): 20 Euro
Children up to 6 years old: Free
Take the blue metro line in the direction of Egaleo and change at Monastiraki. From Monastiraki you need to take the green line electric railway to Piraeus
Once you arrive in Piraeus you will need to walk the green route below from the station to the Hellenic Seaways ticket office located inside the port opposite where the catamarans leave for the Saronic Gulf and Spetses