compose icon indicating copy to clipboard operation
compose copied to clipboard

Feature Request: `docker-compose config` Command

Open behemphi opened this issue 11 years ago • 7 comments

It would be pretty nice to have a docker-compose validate command that would validate the structure of the YAML file. The specific use case I have in mind is for CI pipelines.

  • Return true if valid YAML of Docker-Compose format
  • Return false otherwise

behemphi avatar Sep 01 '15 16:09 behemphi

I've been thinking about this, I think it's a good idea. I was considering naming the command docker-compose config instead of validate.

The default action would be:

  • validate the config
  • on success print the config to stdout with variables interpolated and with extends merged in, and exit status 0
  • on failure print the error to stderr and exit status 1

With -q don't print the config, only errors With --services only print the service names (in correct dependency order), not the full config (replaces #1077)

dnephin avatar Sep 01 '15 16:09 dnephin

The command name is not terribly important to me, and config makes sense for sure.

Your idea on the output is much better than my own. Helps with debugging at development time too that way.

+1 for @dnephin

behemphi avatar Sep 01 '15 16:09 behemphi

Yeah, this is a great idea. See also the featureset I sketched out in https://github.com/docker/compose/issues/1498, which would make shell completion much cleaner and less buggy.

aanand avatar Sep 01 '15 18:09 aanand

Oh yes, I think these could definitely be merged. What do you think about naming (service vs config) ?

dnephin avatar Sep 01 '15 18:09 dnephin

config makes sense to me if (by default) it's going to output the full YAML.

However, looking at #1498 again, the --with-running-container and --with-stopped-container commands make it begin to feel like conflation. (One command to either print out YAML or list services that have a container running?)

aanand avatar Sep 01 '15 20:09 aanand

Ya, I agree with that. --with-running-container and --with-stopped-container feel a bit like they could be provided by ps. The distinction I was running with was:

  • config - never hits the api, only deals with values from the config, prints config or parts of it (service names)
  • ps - hits the api, lists containers

dnephin avatar Sep 01 '15 20:09 dnephin

$0.02

My intent was around keeping a compose file in a project and having my CI system validate it. @dnephin suggestion extends that suggestion to help with the development.

ps is an operational tool to tell me, as an ops person, what is running at any given time. I would exercise this in a "trusty but verify" situation, or when something is wrong (alert comes in) and I use the command to see if a service is down according to docker-compose.

TL;DR

I see these functions as orthogonal in purpose and intent.

behemphi avatar Sep 02 '15 01:09 behemphi