ERROR: Service "xxx" uses an undefined network "xxx"

32,914

Solution 1

You need to add this network to the Compose file as external network like this:

networks:
  frontend-network:
    external: true

You can read about this in the docks here: https://docs.docker.com/compose/compose-file/compose-file-v3/#external-1.

Solution 2

You need to create a user-defined network with:

docker network create etl_dev

After that, make sure you added it to the yaml with top-level networks:, which goes at the same level of services.

version: "3.9"

networks:
    etl_dev:
        external: true

services:
    local_database:
        image: postgres:12
        networks:
            - etl_dev
        volumes:
            - /home/local_postgres_data:/var/lib/postgresql/data
        environment:
            POSTGRES_USER_FILE: /run/secrets/etl_pg_usr_v1
            POSTGRES_PASSWORD_FILE: /run/secrets/etl_pg_pass_v1

If you are using swarm, make sure you add -d overlayto the docker network create command. See Network docs.

Share:
32,914
WhoAmI
Author by

WhoAmI

Updated on October 05, 2021

Comments

  • WhoAmI
    WhoAmI over 2 years

    It keeps saying me that this network is undefined. ERROR: Service frontend-network uses an undefined network frontend-network However, I see that there is such network with docker network ls. What am I missing :( I need your help. I've read a lot about it google, but couldn't find the right solution.

    version: "3.3"
        services:
          web:
            build: ./Docker
            container_name: apache
            ports:
            - "80:80"
            volumes:
            - /home/denis/public-html:/usr/local/apache2/htdocs/
            restart: always
            networks:
            - frontend
            labels:
            - webstack
          mara:
            image: mariadb:latest
            container_name: mara
            ports:
            - "3306:3306"
            volumes:
            - ~/MariyaDb:/var/lib/mysql
            depends_on:
            - "web"
            restart: always
            networks:
            - frontend
            labels:
            - webstack
            environment:
            - MYSQL_ROOT_PASSWORD=example
          adminer:
            image: adminer
            container_name: adminer
            ports:
            - "8080:8080"
            depends_on:
            - "mara"
            restart: always
            networks:
            - frontend-network
            labels:
            - webstack