All these terms refer to a vessel which is secured in a more or less fixed position.
When a vessel is in port to collect/disembark passengers or load/discharge cargo it will be, in a sense, connected to the dock (the functional area of pier) and is therefore 'docked'. A docked ship is typically a large one and will have several crew present on it, even when it is there overnight. Generally a ship is docked for a specific purpose, and when that task is complete the vessel will move on.
A berth, on the other hand, is a bit like the nautical equivalent of a parking space. Typically you buy one or lease one for a long period as somewhere to store your boat. To maximise space, 'berthed' vessels are typically kept perpendicular to (pointed at) the main jetty or pier, rather than a docked ship which is typically parallel to (in line with) the dock.
Any ship which is secured by ropes to a permanent fixture is 'moored' to that fixture. So 'moored' can be quite a broad description, although it is most appropriately used to described a vessel which is being kept at 'moorings'. Moorings are areas of water where boats and yachts can be secured to a fixed object on the seabed, usually a large concrete block with a rope attached and a buoy on the end. They are cheaper than berths to rent and are more secure (people cannot simply walk up to your boat). They tend to be used for the storage of boats or yachts when not in use, so moored vessels tend to have no one on board.
The most independent way to secure a vessel is to drop anchor. So long as the anchor has a certain amount of purchase on the seabed the ship will not move too far from its current location and is therefore described as being 'anchored'. This is the most independent but also the least secure way to station your boat, and as such a ship which is anchored is usually only staying in place for a short time and will almost always have someone on board.