Skip to content

links not work for network_mode: "bridge" #9053

@wangliangliang2

Description

@wangliangliang2

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions