Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).

Do you still use version in Docker compose?

1 min read

For those who’ve been working with Docker Compose for a while, the ‘version’ property at the top of your docker-compose.yml file might be a familiar sight. However, times have changed. This property is now officially considered obsolete.

Consider the following docker compose file:

version: '3.9'


services:
  db:
    image: postgres:10.0-alpine
    volumes:
      - ./db:/docker-entrypoint-initdb.d/

  api:
    build: api
    image: dockersamples/wordsmith-api
    deploy:
      replicas: 5

  web:
    build: web
    image: dockersamples/wordsmith-web
    ports:
     - "8080:80"

If you try to run docker compose up, you might see the following warnings:

WARN[0000] /Users/moby/compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 3/3
 ⠹ api [⠀⠀⠀⠀] Pulling                                                         5.3s 
 ⠹ web [⠀⠀⠀⠀] Pulling                                                         5.3s 
 ⠹ db [⣿⣿⣿⠀⠀⠀⠀⠀

Why is it Obsolete?

Originally, the version property was used to specify the schema version of the Compose file. This was helpful for backward compatibility. However, Docker Compose has evolved, and it now uses the latest Compose Specification by default. This means that specifying a version is redundant and can even lead to warnings.

How Does Docker Compose Handle Compose Files Now?

Docker Compose primarily relies on the Compose Specification to interpret your docker-compose.yml file. This specification is constantly updated to include new features and improvements. When you use Docker Compose, it automatically applies the latest supported schema to your file.

What Does This Mean for You?

  • Remove the version property: It’s safe to delete the version property from your docker-compose.yml files. It won’t affect your Compose file’s functionality.
  • Embrace the latest Compose Specification: Take advantage of the newest features and improvements offered by the latest Compose Specification.
  • Ignore warning messages: If you still have the version property in your files, you might see warning messages. These can be safely ignored.

Conclusion

While the version property might have been essential in the past, it’s no longer necessary in modern Docker Compose workflows. By removing it, you can simplify your Compose files and stay up-to-date with the latest features.

Remember: The focus should be on the content of your Compose file, defining your services, networks, volumes, and other components, rather than worrying about the specific version.

Would you like to learn more about specific features in the latest Compose Specification?

Reference:

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).
Join our Discord Server
Index