Code Monkey home page Code Monkey logo

Comments (4)

xihan88 avatar xihan88 commented on September 13, 2024

Possibly related issue: moby/moby#33661

from libcompose.

vito-c avatar vito-c commented on September 13, 2024

@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

from libcompose.

vito-c avatar vito-c commented on September 13, 2024

@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.

from libcompose.

vito-c avatar vito-c commented on September 13, 2024

I will make a PR with this so it's easier to see the change

from libcompose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.