Network aliases in multicontainer setting

Good day,

I am trying to setup a custom network infrastructure, as in the future we will want to have containers that are restricted in their connection to other containers.

I tried it basically as depicted in the docker compose in this thread:


Multicontainer networking between containers

Product support

So I’m trying to connect two containers in both ways, one of them is a socket server with chat inside, so links or depends_on won’t work, I need the networks feature of docker compose.
The docker-compose file I’m using is:
version: ‘2’
services:
socket_server:
build: ./socket_server
privileged: true
ports:
– “3333:3333”
networks:
main:
aliases:
– socket_server
ruby_test:
build: ./ruby_test
privileged: true
expose:
– “3000”

Here is a part of my docker compose as an example

version: '2.1'

networks:
  x: {}
  y: {}

services:

  a:
    build: './a'
    privileged: 'true'
    restart: 'always'
    cpu_quota: '400000'
    cpuset: '2,3'
    mem_limit: '1024m'
    hostname: 'a'
    networks:
      x:
    expose:
      - '6379'

  b:
    build: './b'
    privileged: 'true'
    restart: 'always'
    cpu_quota: '100000'
    cpuset: '0,1'
    mem_limit: '256m'
    hostname: 'b'
    networks:
      x:
    expose:
      - '6379'
      - '6380'

Is what I tried, when running “balena inspect <numberStuff>_a” I can see in the bottom most section, that the network x has an alias entry of what seems to be a sha hash but no alias “a” as it has when using the default network. I can “ping a” from the container a itself, but not from another container, like b.

This is more than I got with what I would’ve expected to work in the first place, which is:

version: '2.1'

networks:
  x: {}
  y: {}

services:

  a:
    build: './a'
    privileged: 'true'
    restart: 'always'
    cpu_quota: '400000'
    cpuset: '2,3'
    mem_limit: '1024m'
    networks:
      x:
        aliases:
          - 'a'
    expose:
      - '6379'

  b:
    build: './b'
    privileged: 'true'
    restart: 'always'
    cpu_quota: '100000'
    cpuset: '0,1'
    mem_limit: '256m'
    networks:
      x:
        aliases:
          - 'b'
    expose:
      - '6379'
      - '6380'

In which case I can not even “ping a” from a itself. Pinging the SHA hash does work, but is of no use, as it changes frequently (on rebuild i presume)

Is this behaviour a bug? Should the aliases be added or should at least the containername be added as an alias per default, like in the case of the default network? Is there a way for me to work around this?

EDIT:
Also as additional info, when I push a version, that just adds the aliases to the networks in the docker compose, the containers do not restart, but instead just show as being on the new commit immediately.
In case this might give anyone a hint or something.
I just tried both hostname and aliases in the same dockerfile, but it results in the same behaviour as just using the hostname. Seems like the aliases don’t have any effect at all.

EDIT:
Self suggested workaround would be to parse the IP of each container from “ifconfig”’s eth0 interface and put it in a designated file on a shared volume, from which other containers can read it and connect to it, if they are on the same network. I would love a more elegant solution, remaining in the docker compose, though, if possible.

Thanks for your help and greetings,
Tarek