podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

RFE: Support network aliases

Open larsks opened this issue 6 years ago • 8 comments
trafficstars

A docker-compose.yml file may define one or more aliases for a container, such that other containers in the same compose can use those aliases rather than the container name to resolve its ip address. E.g. from the documentation:

services:
  some-service:
    networks:
      some-network:
        aliases:
         - alias1
         - alias3
      other-network:
        aliases:
         - alias2

Support this in podman-compose would permit a wider range of docker-compose setups to be used without modification.

This would require containers/libpod#4530 to be implemented first.

larsks avatar Nov 18 '19 20:11 larsks

Does this problem still exist? I am not able to start a container using aliases with podman-compose at the moment... I always receive a KeyError on startup:

  File ".../python3.9/site-packages/podman_compose.py", line 558, in assert_cnt_nets
    net_desc = nets[net] or {}
KeyError: "system={'aliases': ['db']}"

Using the following compose.yaml:

version: "3.9"
services:
  mariadb:
    image: mariadb:10.6
    networks:
      system:
        aliases:
          - db
      web:
        aliases:
          - db
networks:
  default:
    name: "system"
  web:

Schlumpf9 avatar Dec 25 '21 16:12 Schlumpf9

quote from podman manpage

   --network-alias=alias
       Add network-scoped alias for the container.  NOTE: A container will only have access to aliases on the first network that it joins. This is a limitation that will be removed in a later release.

so regarding

version: "3.9"
services:
  mariadb:
    image: mariadb:10.6
    networks:
      system:
        aliases:
          - sysdb
      web:
        aliases:
          - webdb
networks:
  default:
    name: "system"
  web:

@rhatdan do you suggest a specific sequence of podman commands to acchive that

$ podman network myproj-system
$ podman network myproj-web
$ podman run -ti --rm --network myproj-system --network-alias sysdb --network myproj-web --network-alias webdb  busybox /bin/sh

muayyad-alsadi avatar Dec 25 '21 18:12 muayyad-alsadi

@Schlumpf9 I've just pushed a fix that handles dicts and fixes KeyError

your case would work because in both it's called db

muayyad-alsadi avatar Dec 25 '21 19:12 muayyad-alsadi

I cannot even use network alias at all. if i use the compose file above, i will get

File ".../python3.8/site-packages/podman_compose.py", line 1128, in _parse_compose_file
    raise RuntimeError(f"missing networks: {missing_nets_str}")

crazytaxi824 avatar Jan 15 '22 13:01 crazytaxi824

@crazytaxi824 you are not using latest code, please upgrade to latest code using

pip3 install --user https://github.com/containers/podman-compose/archive/devel.tar.gz

muayyad-alsadi avatar Jan 15 '22 18:01 muayyad-alsadi

@muayyad-alsadi thanks a lot.

crazytaxi824 avatar Jan 16 '22 00:01 crazytaxi824

@crazytaxi824 you are not using latest code, please upgrade to latest code using

pip3 install --user https://github.com/containers/podman-compose/archive/devel.tar.gz

This seems to fix the problem. It would be great if this could be released some time in the future so distributions could add this fix to their repositories. It seems the last release happened last december :)

peacememories avatar Jun 07 '22 09:06 peacememories

Yep would if good if this could be released. Had to use the devel one to get it to work.

pyrossh avatar Jun 15 '22 14:06 pyrossh

Hi, Got the same issue on my side Do you have any plan about a next release ? (the last one is from 2021-12-21, 4 days before the fix) And: no, I don't want to pip install devel 🙂 Regards

gwallet avatar Mar 22 '23 11:03 gwallet

I was very busy lately but the reason I did not release the branch there is a breaking change regarding putting all containers in a single pod or not. putting all containers in a single pod is a desirable feature but to release it I need to do the following

undo that or make it default to "in_1pod=false" then make a minor release then redo it then make another release with major version bump

muayyad-alsadi avatar Mar 22 '23 12:03 muayyad-alsadi