Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect to named external network #35

Closed
wants to merge 5 commits into from
Closed

Cannot connect to named external network #35

wants to merge 5 commits into from

Conversation

cplepage
Copy link
Contributor

@cplepage cplepage commented Jul 17, 2023

Since external networks aren't pushed into the networks array, when a service container tries to find this particular network to connect to, the network is undefined.

cplepage and others added 5 commits July 17, 2023 16:28
After more thorough investigation, tried to reproduced a closer behaviour to native docker compose CLI
@cplepage cplepage closed this Jul 20, 2023
@adora-tech
Copy link

@apocas
Thank you for merging PR #38.
This step was fixed.

Without this PR #35 in the context of the external network, a new network is created without being necessary.
I consider that the changes from network.js must be merged.

Please help us with this PR to fix this situation.

Thank you!
Iulius Ciorica

@AndreasHeine
Copy link
Contributor

@adora-tech i guess there is always a default network for each compose as default!?

otherwise you need to do something like that:

networks:
  default:
    external: true
    name: none

@AndreasHeine
Copy link
Contributor

https://docs.docker.com/compose/networking/

By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

@adora-tech
Copy link

@AndreasHeine

Hello,

I'm not an expert in Docker, but while testing with dockerode-compose and docker compose cli, I noticed some differences.

You may be right, the expectations are that dockerode-compose and docker compose cli using the same docker-compose.yml file will broadly have the same behavior.

docker network create app

In my case, the file has the following content:

version: "3.9"
networks:
  app:
    name: app
    external: true
volumes:
  db:
    driver: local
services:
  db:
    image: postgres:latest
    restart: always
    environment:
      - POSTGRES_USER=app
      - POSTGRES_PASSWORD=app
      - POSTGRES_DB=app
    networks:
      - app
    volumes:
      - db:/var/lib/postgresql/data
  app:
    image: registry.wsl.local/iulius.ciorica/starter-kit:latest
    restart: always
    networks:
      - app
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.app.rule=Host(`app.wsl.local`) && PathPrefix(`/starter-kit`)"
      - "traefik.http.routers.app.tls=true"
      - "traefik.http.routers.app.entrypoints=web-secure"
      - "traefik.http.services.app.loadbalancer.server.port=8080"
      - "traefik.http.routers.app.service=app"
    expose:
      - 8080
    depends_on:
      - db

and without this PR, an additional network is created, with name starter-kit_default

Considering the above, this additional network should not be created.

Thank you,
Iulius Ciorica

@AndreasHeine
Copy link
Contributor

"app" depends on "db":

why you need an extra network (external defined from the compose file)?

all containers in the compose file can natively communicate with each other via the default network (and via container names which is nice) as mentioned in my comment above!

@adora-tech
Copy link

Again, you may be right, but I choose to use more networks(one for each container), this is my choise ...

Disable inter-container communication

The architecture is much more complex and I use a reverse proxy in front of the containers ...
If you have something for or against this PR, you can argue, maybe I was wrong ...
What I want to talk about is the fact that it behaves differently as I stated above.

That's all

@AndreasHeine
Copy link
Contributor

AndreasHeine commented Sep 25, 2023

tbh, i just try to understand your use-case... i actually dont know the reason why this PR has been closed...

maybe i can help with another PR to prevent the creation of the default network... but my assumption is its more an issue with the services.js/serviceTools.js not with the network.js

edit:
maybe an option in the up() params!?

@cplepage
Copy link
Contributor Author

cplepage commented Dec 8, 2023

Hi @AndreasHeine ,

Sorry for not noticing your input here! Unfortunately I closed this PR, because I really needed to move forward and I wasn't getting any responses from a maintainer, so I forked and went on.

Today, I took the time to see if I still needed to keep up my fork and doing so, I stumbled on your merged PR. As I'm try to figure out if we fix the exact same use case, I know my stuff has evolve too, so I will drop my fork and go back to using and contributing to this current repo.

Thanks a lot for your work here!

bngams added a commit to bngams/dockerode-compose that referenced this pull request Jan 11, 2024
Cannot connect to named external network
Use fix from this issue apocas#35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants