-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Treat services prefixed with . as hidden or abstract #4747
Comments
Duplicate of #2578 ? |
Fair enough. I'm rather in favor of a solution like the #4461 PR. I think it has some advantages over your proposal, namely:
Let me know what you think, and if there are use cases you believe #4461 wouldn't address. |
Cool, I hadn't noticed #4461! That does look like a much more inclusive solution. I'll look into it more closely. |
I'm closing this. #4461 provides opportunities to support more than just anchors for services. |
Problem Description
Docker Compose files are YAML files. In YAML, anchors can be used to reference and duplicate content across a document. For example, the following YAML declares an anchor named base that is applied to foo.
Source:
Result:
It is possible to use YAML anchors in Docker Compose files so that one service is used as the base of another service. For example, the following snippet declares a service named
.function
that has an anchor namedfunction
, which is used as the base of the function1 and function2 services.In the above example, the
.function
service is meant to be used as an abstract definition for the concretefunction1
andfunction2
services, and should not be run as an actual service by Docker Compose. Service names cannot contain.
in their names, so the above example cannot be deployed at all usingdocker stack deploy
.Proposed Solution
I propose that a future Docker Compose file format treat services starting with
.
as hidden, so that they can be easily used with YAML anchors. These hidden services would not be deployed and can be ignored by Docker Compose anddocker stack deploy
. This is similar to GitLab CI YAML files, where jobs starting with a.
are considered hidden.Example Usage
In the Functions as a Service project, functions are declared as individual services in a Docker Compose file. There can be a large number of functions, all with nearly identical service declarations, resulting in lots of repeated lines. Here is an example of a Docker Compose file with four functions as services written in the Docker Compose 3 file format, and then with a hidden service. This example is based on the docker-compose.yml file in alexellis/faas.
Docker Compose version 3 format
With YAML anchors and . hidden service
With anchors, the declarations for
echoit
,wordcount
,base64
, anddecodebase64
are much more terse, and contain only the parts specific to them.Related Issues
This is partially related to the discussions about the lack of support for
extends
in version 3. See #4315 and moby/moby#31101. However, this does not replace the functionality offered byextends
because YAML anchors do not offer Docker Compose's behaviour for combining lists and dictionaries.The text was updated successfully, but these errors were encountered: