Networks and port forwarding

$ docker network create futurama
$ docker run -d --network futurama --name postgres postgres:9.5.6-alpine

$ docker run -d --network futurama -p 8787:8787 --name rstudio rocker/rstudio
$ docker network inspect futurama | jq ".[].Containers"
{
"59e36dd086141d5e6cbe433271b4934ed06132817fe7b82d6e8ea65e3ad3396b": {
"Name": "rstudio",
"EndpointID": "b9454486816e27d17095a97e60c9b6f829637a16bf719f30032a5a3af59e650f",
"MacAddress": "02:42:ac:14:00:03",
"IPv4Address": "172.20.0.3/16",
"IPv6Address": ""
},
"fe1f3cf25315b3352de5a032ea3d8c6d3582606a4e15b265d016abe3674d9d3c": {
"Name": "postgres",
"EndpointID": "ceff985240a907843af3006dbd483eb42e1d0ae278a994d3fe01e4195cee2589",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
}
}
# ping postgres inside docker network
$ docker run --rm --network futurama alpine ping -c 1 postgres
PING postgres (172.20.0.2): 56 data bytes
64 bytes from 172.20.0.2: seq=0 ttl=64 time=0.136 ms
...
# check whether rstudio is available on port 8787 on localhost
$ nc -zv localhost 8787
Connection to localhost 8787 port [tcp/*] succeeded!