Is there some globally admitted coding conventions for docker-compose files? Below is a sample docker-compose.yml from a small project we have here:

version: 3
    driver: 'bridge'

    build: .
    - net
    - 3000:3000
    image: redis:alpine
    - net
    image: "app/test_clients"
      replicas: '3'

The quoting is especially inconsistent. Sometimes quotes are used around text and numerical literals. Sometimes they aren't. Sometimes single quotes are used, sometimes double quotes are used instead. The various example in the official docker-compose documentation seems relatively inconsistent in that area too.

This is valid YAML. And YAML is very permissive about quoting and, as far as I know, quotes could simply be omitted in most of the cases. I know this is probably a matter of internal policy but I wonder if there are some commonly accepted "best practices" in that matter.

  • 2
    This answer seems well considered stackoverflow.com/a/22235064/329496
    – simbo1905
    Commented Feb 5, 2019 at 22:36
  • @simbo1905 Could you post an answer?
    – 030
    Commented Dec 24, 2019 at 17:19
  • According to this Q&A one could also use docker-compose config. I tried it and it returned ERROR: Version in "./docker-compose.yml" is invalid - it should be a string. and WARNING: Some services (client) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use docker stack deploy` to deploy to a swarm.`.
    – 030
    Commented Dec 24, 2019 at 17:29

2 Answers 2


One could use Composerize to create a consistent docker-compose.yml.

There seems to be two options. Options one is to enter some docker run command, e.g. docker run app/test_clients on their website, which will return:

version: '3.3'
        image: app/test_clients

Or use the command line: composerize docker run app/test_clients.


You could also introduce a YAML linter to your CI to ensure that a consistent docker-compose.yml format will be enforced, like yaml-lint. According the docs it should be possible to define a certain format. If the pipeline fails, then the developer has to apply changes in order to fix the build.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.