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

links not work for network_mode: "bridge" #9053

Closed
wangliangliang2 opened this issue Dec 19, 2021 · 7 comments
Closed

links not work for network_mode: "bridge" #9053

wangliangliang2 opened this issue Dec 19, 2021 · 7 comments
Assignees

Comments

@wangliangliang2
Copy link

the following yaml will automatic create new network, then nginx2 can ping nginx1.

version: '3'
services:
    nginx1:
        image: nginx:alpine
        container_name: "nginx1"
    nginx2:
        image: nginx:alpine
        container_name: "nginx2"

but I don't want it to create new network , so I use the following yaml. it turns out that nginx2 can't ping nginx1.
it shows me: ping: bad address 'nginx1'.

version: '3'
services:
    nginx1:
        image: nginx:alpine
        network_mode: "bridge"
        container_name: "nginx1"
    nginx2:
        image: nginx:alpine
        network_mode: "bridge"
        links:
            - nginx1
        container_name: "nginx2"

but when you use the following code , nginx1 and nginx2 will add to default bridge network and nginx2 can ping nginx1.

docker run -d --name nginx1  nginx:alpine
docker run -d --name nginx2 --link nginx1 nginx:alpine

docker inspect nginx2 will show then the follwing code.

"Links": [
                "/nginx1:/nginx2/nginx1"
            ],

so, is there a way to fix this problem when docker-compose use default bridge can't link other service?

@ghislain-bernard
Copy link

ghislain-bernard commented Mar 7, 2022

Hello,
I have exactly the same problem links tag KO into bridge mode.... I went back to docker-compose version 1.29.2.
Best regards.

@adamjacobmuller
Copy link

I have this same issue, works fine with docker-compose but doesn't work with docker compose

@navneet0693
Copy link

I have the almost same issue where I am using "depends_on" instead of links and the containers are not able to see each other when I use docker compose. So, I am forced to revert to docker-compose v1

@navneet0693
Copy link

The documentation here: https://docs.docker.com/network/bridge/ says the containers should be able to see each other using links but links is legacy.

@laurazard laurazard self-assigned this Jun 18, 2022
@laurazard
Copy link
Member

Hiya @wangliangliang2 (and everyone else facing the same issue): I believe this commit should address this issue. Please check again when the next version is released to see if the issue is resolved!

@navneet0693
Copy link

navneet0693 commented Jun 18, 2022

@laurazard Thank you for this! <3 Also, I would like to throw out one observation that the depends_on on Docker for Mac is working fine and the containers are able to connect to each other using the services name. While this doesn't work on Linux. Trust me, I have read a lot of documentation related to Docker compose & network but it doesn't mention this behavior or anything related.

My PR is: goalgorilla/drupal_social#374

For example:

Considering the following in compose.yaml, container1 will be able to access container2 using "name", but this works on Docker for Mac but not on Ubuntu using Docker CE.

services:
  container1:
    image: drupal
  container2:
    image: mariadb
    depends_on:
      - container1

@laurazard
Copy link
Member

I'm going to close this issue since the original problem has been fixed/shipped. @navneet0693 feel free to open another issue for the problem you're dealing with.

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

No branches or pull requests

5 participants