Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 742
WhoAmI Avatar asked Oct 01 '18 08:10

WhoAmI


3 Answers

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.

like image 61
takacsmark Avatar answered Nov 14 '22 20:11

takacsmark


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.

like image 37
RicarHincapie Avatar answered Nov 14 '22 20:11

RicarHincapie


Specify the type of driver for your network in your Docker compose file like this:

networks:
  frontend-network:
    driver: <driver-name>
like image 1
khwilo Avatar answered Nov 14 '22 20:11

khwilo