Docker Community Forums

Share and learn in the Docker community.

[1.22.0] Network overwrite configuration


(Boskiv) #1
➜  dev-env git:(master) ✗ docker-compose version
docker-compose version 1.22.0, build unknown
docker-py version: 3.5.0
CPython version: 3.7.0
OpenSSL version: OpenSSL 1.0.2p  14 Aug 2018

compose/network.yml:

version: '3'
services:
  postgres:
    networks:
      - devenv
networks:
  devnev:
    driver: bridge
    ipam:
     config:
       - subnet: 172.5.0.0/16

compose/postgres.yml

version: '3'
services:
  postgres:
    image: postgres:10-alpine
    ports:
      - 5432:5432
    env_file:
      - ../.env
    networks:
      - devenv

When run up:

➜  dev-env git:(master) ✗ docker-compose -f compose/network.yml -f compose/postgres.yml up
WARNING: Some networks were defined but are not used by any service: devnev
ERROR: Service "postgres" uses an undefined network "devenv"
➜  dev-env git:(master) ✗

Where I missed up ?


(Paulxroot) #2

The main reason is probably that you misspelled “devenv” once as “devnev” in the network.yml network definition.

The following is what I wrote before I noticed the misspelled network name:

It would make more sense to just have one compose file for your service and the network definition.
If your service postgres and your network devenv do belong together, why not put them in one compose file together, like this:

version: '3'
networks:
  devenv:
    driver: bridge
    ipam:
     config:
       - subnet: 172.5.0.0/16
services:
  postgres:
    image: postgres:10-alpine
    ports:
      - 5432:5432
    env_file:
      - ../.env
    networks:
      - devenv

You can find the network section of the compose file reference here: https://docs.docker.com/compose/compose-file/#network-configuration-reference

If this is not what you want, then another option is to declare the network as external. That means docker will expect that network to be already existing when “executing” the compose file. Make sure to create it before, e.g. with ‘docker network create …’


(Boskiv) #3

Thanks, you right.
How to make this topic resolved ?