Naming networks in a docker-compose file.

This is a part of the 100 Days To Offload challenge.

Small reminder for myself that should not just stay as a comment in one of the projects at work: the ability to name networks was added/finalized in the v3.5 docker compose schema. Like so:

networks:
  blog:
    name: wpblog

See the GitHub issue for discussion and then the PR.

But Ru, couldn’t I already do this in the v2.x schema?

Between version 2 and version 3 of the compose-file schema, here’s what the Docker docs say (emphasis mine):

Designed to be cross-compatible between Compose and the Docker Engine’s swarm mode, version 3 removes several options and adds several more.

https://docs.docker.com/compose/compose-file/compose-versioning/#version-3

Naming networks is also allowed starting version 2.1 of the schema.

You can use whichever one you like between 2.1+ and 3.5+, even if just using compose and not the swarm mode. Unless you have some specific reason to be using the other one.

v2.1 is supported since 16 November 2016 with corresponding Docker and Compose versions. v3.5 is supported since 18 December 2017 with corresponding Docker and Compose versions.

Last updated on 28 August 2021. Thanks to Gabriel for helping me make some improvements. Join the discussion by writing me an email.