Docking
Docking was officially introduced in KSP 0.18 and allows separate ships to join into a single entity that is controlled as one and allows the transfer of resources (but not yet Kerbanauts) between connected modules.
Contents
Using the docking controls
The faintly purple button around the bottom left corner of the screen (just below the green staging button, and above the blue map button) sets your ships into docking mode. In docking mode your main engines are shut off and your normal WASD controls map to RCS translation maneuvers instead.
To dock with a nearby object (see the basic maneuvers page for how to rendezvous with another object in orbit), start by rotating your ships so their docking ports are facing each-other. Remember to toggle any docking-port covers if necessary. Also keep an eye out for how your ships will connect and make sure you won't run into solar panels or other modules on your approach.
Right click the docking port on your ship and hit "control from here". Now activate docking mode. What is happening now is that docking port will be seen as the "center" of your ship. Your WASD keys will be used for moving sideways (known as "translation") on a plane that is perpendicular with your docking port's direction. Throttle-up (Shift) will approach your target ship by moving forward (specifically, whichever way your docking port is pointing) and throttle-down (Ctrl) will move away.
Once your docking ports are very close (or touching) they will magnetically clamp to each-other and you will have successfully docked. The tolerance for the clamps is quite generous, however, it can take some time for it to kick in - so once you get your ports in close proximity, just wait a bit before trying to get any closer (and possibly damage your ships).
Note that you don't have to be in docking mode to dock - if you manage to align your docking ports using the regular controls, everything will still work.
While docked, you can transfer resources (fuel, etc) by clicking on a tank, and then alt+right clicking on another target and pressing the desired In/Out switches of the windows that pop up.
As of 0.18.2, Kerbanauts have to be transferred manually using EVAs.
To undock simply right click either of the docking clamps and hit undock.
Possibilities for docking
Docking gives you some great new abilities.
In-orbit spacecraft assembly
There is a limit of how large your rockets can be, and most of them will be used just to get into orbit. So what can be done to build even larger crafts for more exciting interplantary missions? Launch the individual components into orbit on separate rockets, and then dock them together into one giant space ship.
The cancelled Constellation program by NASA was planning to use this method for manned missions to moon and mars[1].
Detachable landing crafts
This method was used during the human moon landings [2], and it can be equally useful for the Kerbin. When you do a landing mission and have the intention of getting back to Kerbal, don't take all the fuel for the return flight to the surface of whatever planet you are visiting. Undock a lander with just enough fuel to get to the surface and back, and redock it with the return stage when it's back in orbit. You can save a lot of fuel that way, because the lander doesn't need to carry all the return fuel to the surface and back into orbit.
<references>