Docker compose yml alternatives - docker

Yml depends on formatting for nested structures, and for inaccurate filled files it is very hard to find out all format errors that violate original meaning. Is there any alternative to yml format for docker-compose configuration file?

TLDR; No.
From Documentation
The Compose file is a YAML file defining services, networks and volumes. The default path for a Compose file is ./docker-compose.yml
Now to answer on your arguments regarding the format and the difficulty to find errors violating original meaning:
yamllint is a first tool that can help your validate your overall yaml syntax (whatever the target expected format).
docker-compose config will read your docker-compose.yml file in and report errors if it does not comply with the expected compose file format.

Related

Docker compose invalid top-level property "name"

I'm trying to set up my docker project name, and according to documentation there should be the docker compose file top-level property 'name' to do so, but I can't figure out how to use it.
I found references at the end of The Compose application model section and in the specific Name top-level element section, but none of the two have an example and I still get an error when trying to run docker-compose up -d
docker-compose.yml file
version: "3.3"
name: "project-name"
services:
# ...
The error
ERROR: The Compose file './docker-compose.yml' is invalid because:
Invalid top-level property "name". Valid top-level sections for this Compose file are: version, services, networks, volumes, secrets, configs, and extensions starting with "x-".
You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
To use the compose-spec, you need a tool that parses that spec (like docker compose with a space) and you shouldn't be specifying a version. If you are parsing the file with an older version of docker-compose or a tool that doesn't use the spec, these newer fields won't work and you'll likely see it fall back to version 1 without a version field.
With version: "3.3", that expects the format defined in the version 3 documentation.

I need help. Why error docker-compuse, wireguard?

Error: You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g
"2.2" or "3.3") and place your service definitions under the
services key, or omit the version key and place your service
definitions at the root of the file to use version 1. For more on the
Compose file format versions, see
https://docs.docker.com/compose/compose-file/
Yaml:
You have a typo in the first line. Probably it should start with version: 3.3 link.

Overriding VS 2017's docker-compose dynamically created entrypoint

When using the integrated docker-compose structure in Visual Studio 2017, the system provides visibility to a two-tiered docker-compose structure.
docker-compose.yml and docker-compose.override.yml
Settings in the override take precedent over those in the former file. When the file is actually executed, it includes a third, auto-generated Docker compose file ...
docker-compose.vs.*configuration*.g.yml
This latter file contains mostly values related to debugging interactions and mapping volumes in for code you want. Generally, you wouldn't want to change any of these.
One thing that it does by default is to set the entrypoint which ends up becoming the command for the container. As this file is applied last (after the compose file and the override, it is holding precedence over the other two resulting in not being able to override that entrypoint.
Is there a way around this?

Docker dynamic configuration files

Some of my Docker containers require configuration files (think: JSON, YAML or INI files) that depend on environment variables and/or container arguments.
What is the standard approach to automatically generate those environment files?
Solutions I have considered so far include:
Tiller: but I'm not excited by the idea of adding a ruby gem to my containers.
A custom string replacement script written in the same language as my other applications: but I don't want to include an extra script in all my docker projects.
sed -i s/ENVVAR/${ENVVAR}/g config.json: it works but it's a bit too "raw" for my taste.
Check out confd, highly recommend it for this particular use case of "I want templating with minimal clutter in my image". confd allows you to use a local environment variable backend to template out whatever config file format you want.

use inheritance in docker-compose.yml

I have a lot of services, which use the same basic configuration in docker-compose. Actually most of the configuration is the same, with some minor tweaks.
I have seen that it is somehow possible to inherit values in YAML. Can I use this in docker-compose to define a "default-service" and use this all over in the other services for e.g. docker-compose run? How would I do this?
No, you cannot do that using YAML. The only inheritance like feature in YAML is the Merge Key Language Independent Type and that only works withing one YAML document, not between multiple documents in the same YAML file (separated by ---) and certainly not between different YAML files.
However docker-compose reads docker-compose.yml and if available docker-compose.override.yml, where the values in the second file (if available) override the ones in the first. Combined with the -f option to specify an input YAML file for docker-compose you can use a shared base file with different overrides.
This is a feature of docker-compose and is done on the data loaded from the YAML files, not by combining the YAML files and then loading them.

Resources