Another approach is to connect the containers by binding the ports to the docker0 interface.
All docker containers are connected to this bridge per default (which usually has the ip address 172.17.42.1).
docker run -p 172.17.42.1:8001:8080 --name container1 [image]
docker run -p 172.17.42.1:8002:8080 --name container2 [image]
The containers can access eachother via 172.17.42.1 and the specific port.
A similar solution like @wassgreen provided, but has the advantage that the containers do not have access to the hosts interfaces.
See Advanced networking section --net=host:
[...] but it does let container processes open low-numbered ports like any other root process. It also allows the container to access local network services like D-bus. This can lead to processes in the container being able to do unexpected things like restart your computer. You should use this option with caution.
For more information about this connection via docker0 interface, see Unorthodox docker connection without links.