You can drag the icons on the dock and put them in and out, but is there any way of locking them so you can't do this?
Yes, this is possible. You can open the dock's preferences by right-clicking on a free space of the dock. Probably you will need several tries not to open context menu from an icon - but believe me, there are preferences:
For me the easiest way to open the preference window was the rightmost bottom of the dock (for bottom-placed dock). In the 'behaviour' tab you can lock the icons.
As a complement to the other answer:
The command for the Plank settings UI is:
To find that with your applications launcher in the future (using
gedit text editor):
sudo gedit /usr/share/applications/plank_preferences.desktop
then paste this & save:
[Desktop Entry] Type=Application Name=Plank Settings Exec=plank --preferences Icon=plank Terminal=false Categories=GNOME;GTK;System; X-GNOME-Keywords=Center;Control;Panel;Preferences;System; X-AppInstall-Keywords=Center;Control;Panel;Preferences;System; X-GNOME-Gettext-Domain=switchboard Actions=AboutDialog;
To make changes like the one you mention one can also edit the file
~/.config/plank/dock1/settings which contains detailed description of the possible options. To lock the icons go to line
#Whether to prevent drag'n'drop actions and lock items on the dock. LockItems=false
and change that to