patternMinor
Coding conventions for docker-compose files?
Viewed 0 times
dockerfilesforcomposeconventionscoding
Problem
Is there some globally admitted coding conventions for
Below is a sample
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.
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.
Solution
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.
Or use the command line:
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_clientsOr use the command line:
composerize docker run app/test_clients.Code Snippets
version: '3.3'
services:
test_clients:
image: app/test_clientsContext
StackExchange DevOps Q#6232, answer score: 3
Revisions (0)
No revisions yet.