61

It keeps saying to me that the network is undefined.

ERROR: Service frontend-network uses an undefined network frontend-network

However, I see that there is already such a 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
WhoAmI
  • 1,013
  • 2
  • 9
  • 19

4 Answers4

86

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.

takacsmark
  • 3,933
  • 23
  • 26
13

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.

RicHincapie
  • 3,275
  • 1
  • 18
  • 30
2

setting the default network driver (on bridge) worked for me

https://docs.docker.com/compose/compose-file/compose-file-v3/#bridge

networks:
  frontend-network:
    driver: bridge
fatemeh sadeghi
  • 1,757
  • 1
  • 11
  • 14
1

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

networks:
  frontend-network:
    driver: <driver-name>
khwilo
  • 481
  • 4
  • 9