Is it possible to stop docker compose from creating a default network

By default docker creates a default network when I spin up my 3 containers using docker compose up. Is it possible to stop this from happening by specifying something in the docker-compose.ymal file?

You could add network_mode: bridge to every service within your docker-compose.yml so that this service is put into the bridge-network instead of creating a separate network for every docker-compose.yml.

Of course you can create your own network(s) and put your services into these networks - check the documentation for further information.

I am still slightly unsure how this would stop the the default network from being automatically generated. In my case I have created 2 of my own networks and have put my containers into those networks. This is shown below in the Dockerfile:

version: '3.4'

services:
  provisioning:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: provisioning-build
    ports:
      - 8888:8888
    networks:
      - vts-prov

  verification:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: verification-build
    ports:
      - 8080:8080
    networks:
      - vts-ver

  vts:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: vts-build
    ports:
      - 8081:8081
    networks:
      - vts-prov
      - vts-ver

networks:
  vts-prov:
    ipam:
      driver: default

  vts-ver:
    ipam:
      driver: default


So even with my own networks created when I run docker network ls there is still the services_default network being created as shown below. How can I stop this from happening (so as to only have the 2 networks I specify)?

NETWORK ID     NAME                DRIVER    SCOPE
42c9ecf8a714   bridge              bridge    local
a77231c1ffd6   host                host      local
08b3ae5764d0   none                null      local
e69613e0aff3   services_default    bridge    local
7705c648a5e3   services_vts-prov   bridge    local
fcc4b59bfea6   services_vts-ver    bridge    local

Thank you

The topic title is confusing, Please share your thoughts about why docker-compose would be responsible to create docker0.

If it is just about the default network a compose project deployment creates, then you should be able to prevent it like this:

networks:
  default:
    external: true
    name: none

Or you can customize its name like this:

networks:
  default:
    name: a-name-i-prefer-over-projectname_default

Note: In the service declaration, the network that need to be assigned would be still default. The changed name can be seen on docker engine level, e.g. with docker network ls

1 Like

Apologies for the confusing title. Im new to understanding docker networking but I think what I meant is that docker creates a default network when building and running a container (this could be using docker compose or running individual containers) and I wanted to stop that from happening. Please correct me if my above understanding is incorrect.

However thanks @meyay! Using the first suggestion worked to stop the default network from being created which is what I wanted to achieve

I renamed the topic name, as a default network is only created by a compose project (or with docker swarm for stack deployments). Creating a container with docker run does not create a default network.

Glad you found what you were looking for!

1 Like

Compose by default build your containers as if they are one network connected to each other
There is no way to stop that behavior as docker build every container attached to a network on top of a network driver
However docker provides 5 network drivers
[bridge(default), host, none, macvlan, ipvlan]
if you specifed your netorks in compose file you could use either “none” if you don’t need any networks or “host” if you need a full access to you docker host network
the three other types are treated the same in config and will create a new network for every network you specify or any container without attached network (bridge by default)

keep in mind that you could use external networks so compose don’t create new network but use a pre-built docker network