skip to Main Content

I have a docker-compose with a bridge network called mdb_default, where I have a database.

I want to deploy another docker-compose that connects to that network that already exists, but I don’t know how to define it in the docker-compose.
My file is:

supeset:
    container_name: superset
    build: .
    restart: always
    depends_on:
      - mariadb
    environment:
      MAPBOX_API_KEY: 'pk.eyJ1IjoiamFta2lsbHM1IiwiYSI6ImNrd293aDJyZjA3MGQyd3AzdTJpeXp0dTAifQ.w96chqjB6Nv3PW6_lpQVHQ'
    ports:
      - 8000:8088
    volumes:
      - ./superset-data:/var/lib/mysql
    networks:
      - mdb_defatult
networks:
  mdb_dafault:
    driver: bridge 

What do I need to do to connect to this existing network?

The network information is that I want to connect both is:

        "Name": "mdb_default",
        "Id": "2c69ba9fb42c1d9ca6142ae49c403d44bae5e297b78f4339c4782d3658f3d49c",
        "Created": "2022-05-17T14:17:47.935473033Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"

2

Answers


  1. You can declare an external network in the compose file and then have each service attach itself to that. Here’s the documentation for the flag and another article that shows it in practice a bit more:

    Login or Signup to reply.
  2. As described here: https://docs.docker.com/compose/networking/#use-a-pre-existing-network

    Try:

    supeset:
        container_name: superset
        build: .
        restart: always
        depends_on:
          - mariadb
        environment:
          MAPBOX_API_KEY: 'pk.eyJ1IjoiamFta2lsbHM1IiwiYSI6ImNrd293aDJyZjA3MGQyd3AzdTJpeXp0dTAifQ.w96chqjB6Nv3PW6_lpQVHQ'
        ports:
          - 8000:8088
        volumes:
          - ./superset-data:/var/lib/mysql
        networks:
          - mdb
    networks:
      mdb:
        external:
          name: mdb_default
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search