Closed jordanabderrachid closed 6 years ago
Possibly related issue: https://github.com/moby/moby/issues/33661
@vdemeester what will it take to get this fixed? updating docker vendor to moby?
I just noticed this issue and I saw that if I use two networks the 2nd one works (as long as the 2nd one is not the default).
---
version: '2'
services:
test.env:
container_name: test.env
image: alpine
environment:
FOO: ${ABC:-foo}
command: env
networks:
default:
aliases:
- does.not.work
notdefault:
aliases:
- works
Which brought me to another question. How do you create an alias for an external network in docker-compose v2??
You can't duplicate keys so this won't work
---
version: '2'
services:
test.env:
container_name: test.env
image: alpine
environment:
FOO: ${ABC:-foo}
command: env
networks:
- something:
networks:
something:
aliases:
- dunno
networks:
something:
external: true
@vdemeester I have a "hack" that I was able to implement to get aliases working (at least for my project).
./vendor/github.com/docker/libcompose/docker/service/service.go
+ if len(net.Aliases) >= 1 {
+ client.NetworkConnect(ctx, net.RealName, containerID, &network.EndpointSettings{
+ Aliases: aliases,
+ Links: links,
+ IPAddress: net.IPv4Address,
+ IPAMConfig: &network.EndpointIPAMConfig{
+ IPv4Address: net.IPv4Address,
+ IPv6Address: net.IPv6Address,
+ },
+ })
+ client.NetworkDisconnect(ctx, net.RealName, containerID, true)
+ }
essentially reconnect quickly to the network to trick the docker client into creating the alias.
I will make a PR with this so it's easier to see the change
Description
When defining several network aliases, only one is created.
System Info
Reproduce case
docker-compose.yml
main.go
docker inspect server