Docker-compose external_links not able to connect

前端 未结 3 1842
闹比i
闹比i 2021-02-09 14:03

I have a couple of app containers that I want to connect to the mongodb container. I tried with external_links but I can not connect to the mongodb.

I get

3条回答
  •  抹茶落季
    2021-02-09 15:01

    Documentation at https://docs.docker.com/compose/compose-file/#/externallinks says

    If you’re using the version 2 file format, the externally-created containers must be connected to at least one of the same networks as the service which is linking to them.
    

    Ex:

    Create a new docker network

    docker network create -d bridge custom

    docker-compose-1.yml

        version: '2'
    
        services:
          postgres:
            image: postgres:latest
            ports:
              - 5432:5432
            networks:
              - custom
    
        networks:
          custom:
            external: true
    

    docker-compose-2.yml

        version: '2'
    
        services:
          app:
            image: training/webapp
            networks:
              - custom
            external_links:
              - postgres:postgres
    
        networks:
          custom:
            external: true
    

提交回复
热议问题