An approach I tend to prefer more is by specifying the container's name (network_mode):
services:
mycontainer1:
image: myregistry/my-container1:latest
ports: ['6666:7777']
mycontainer2:
image: myregistry/my-container2:latest
network_mode: container:mycontainer1 # <---