5

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
networks:
  net:
    driver: 'bridge'

services:
  app:
    build: .
    networks:
    - net
    ports:
    - 3000:3000
  redis:
    image: redis:alpine
    networks:
    - net
  client:
    image: "app/test_clients"
    deploy:
      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.

030
  • 13,383
  • 17
  • 76
  • 178
Sylvain Leroux
  • 1,660
  • 2
  • 15
  • 27

2 Answers2

3

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'
services:
    test_clients:
        image: app/test_clients

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

030
  • 13,383
  • 17
  • 76
  • 178
0

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.

030
  • 13,383
  • 17
  • 76
  • 178