mirror of
https://github.com/docker/compose.git
synced 2026-11-17 21:57:19 +00:00
A provider's resource lives outside the compose network: consumers could
only reach it through injected variables carrying a host-published
address — nothing like the compose-native experience of addressing a
service by name at its well-known port.
A provider may now publish where each endpoint of its resource actually
listens:
{"type": "publish-endpoint", "message": "80=localhost:49152"}
The endpoint is announced as seen from the provider's host: the relay —
the component that knows it runs inside a container — rewrites loopback
or unspecified upstream hosts to host.docker.internal (resolved through
its injected host-gateway extra_host); routable addresses pass through.
When at least one endpoint is published, compose deploys a relay
container in place of the service: a minimal TCP forwarder (new relay/
directory, published as docker/compose-relay, overridable with
COMPOSE_RELAY_IMAGE for internal registries) joining the networks of the
services that depend on the provider service, aliased with the service
name. Consumers then use http://<service>:<port> as if the service were
a regular container.
The relay is a first-class project container — canonical name, standard
compose labels including config-hash (label-driven commands run without
the compose file keep seeing the service: ps, logs, stop, down) — plus
the com.docker.compose.relay label declaring its role:
- the reconciler already leaves provider services' containers alone, and
the relay's identity hash (image + routes) makes up idempotent: kept
when routes are unchanged, recreated otherwise;
- process-level commands (exec, cp) refuse a relay — there is no service
process in it to act on;
- the up monitor excludes relays from the containers whose termination
ends an attached up: they are long-lived infrastructure and would
otherwise keep 'up' waiting forever.
The example provider demonstrates the flow behind PROVIDER_DEMO_ENDPOINT
(a detached helper serving a fixed HTTP response), backed by an e2e
scenario asserting the compose-native address works and exec is refused.
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
86 lines
4.1 KiB
Go
86 lines
4.1 KiB
Go
/*
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package api
|
|
|
|
import (
|
|
"github.com/hashicorp/go-version"
|
|
|
|
"github.com/docker/compose/v5/internal"
|
|
)
|
|
|
|
const (
|
|
// ProjectLabel allow to track resource related to a compose project
|
|
ProjectLabel = "com.docker.compose.project"
|
|
// ServiceLabel allow to track resource related to a compose service
|
|
ServiceLabel = "com.docker.compose.service"
|
|
// ConfigHashLabel stores configuration hash for a compose service
|
|
ConfigHashLabel = "com.docker.compose.config-hash"
|
|
// ContainerNumberLabel stores the container index of a replicated service
|
|
ContainerNumberLabel = "com.docker.compose.container-number"
|
|
// VolumeLabel allow to track resource related to a compose volume
|
|
VolumeLabel = "com.docker.compose.volume"
|
|
// NetworkLabel allow to track resource related to a compose network
|
|
NetworkLabel = "com.docker.compose.network"
|
|
// WorkingDirLabel stores absolute path to compose project working directory
|
|
WorkingDirLabel = "com.docker.compose.project.working_dir"
|
|
// ConfigFilesLabel stores absolute path to compose project configuration files
|
|
ConfigFilesLabel = "com.docker.compose.project.config_files"
|
|
// EnvironmentFileLabel stores absolute path to compose project env file set by `--env-file`
|
|
EnvironmentFileLabel = "com.docker.compose.project.environment_file"
|
|
// OneoffLabel stores value 'True' for one-off containers created by `compose run`
|
|
OneoffLabel = "com.docker.compose.oneoff"
|
|
// RelayLabel marks the network relay container compose deploys in place
|
|
// of a provider-managed service (see the publish-endpoint provider
|
|
// message). Its value is a hash of the relay's routes, used to decide
|
|
// whether an existing relay can be kept on the next up. Commands that
|
|
// act on a service's process (exec, ...) refuse relay containers.
|
|
RelayLabel = "com.docker.compose.relay"
|
|
// SlugLabel stores unique slug used for one-off container identity
|
|
SlugLabel = "com.docker.compose.slug"
|
|
// ImageDigestLabel stores digest of the container image used to run service
|
|
ImageDigestLabel = "com.docker.compose.image"
|
|
// ImageVolumeDigestLabel stores the content digest of each `type: image`
|
|
// volume's source image, as "target=digest" pairs joined by ",", so
|
|
// mustRecreate can detect a rebuilt/updated source image independently of
|
|
// the mount Source (which must stay a resolvable name, not a digest).
|
|
ImageVolumeDigestLabel = "com.docker.compose.image-volume-digest"
|
|
// DependenciesLabel stores service dependencies
|
|
DependenciesLabel = "com.docker.compose.depends_on"
|
|
// VersionLabel stores the compose tool version used to build/run application
|
|
VersionLabel = "com.docker.compose.version"
|
|
// ImageBuilderLabel stores the builder (classic or BuildKit) used to produce the image.
|
|
ImageBuilderLabel = "com.docker.compose.image.builder"
|
|
// ContainerReplaceLabel is set when container is created to replace another container (recreated)
|
|
ContainerReplaceLabel = "com.docker.compose.replace"
|
|
// ContainerEngineLabel stores the name of the engine that runs the container
|
|
ContainerEngineLabel = "com.docker.compose.engine"
|
|
// HookLabel identifies an ephemeral lifecycle-hook container and stores the
|
|
// hook type, e.g. "pre_start". It is applied to every container created by
|
|
// runPreStartHook so orphan hook containers from a previous failed run can
|
|
// be found and removed by project+service+hook label filters.
|
|
HookLabel = "com.docker.compose.hook"
|
|
)
|
|
|
|
// ComposeVersion is the compose tool version as declared by label VersionLabel
|
|
var ComposeVersion string
|
|
|
|
func init() {
|
|
v, err := version.NewVersion(internal.Version)
|
|
if err == nil {
|
|
ComposeVersion = v.Core().String()
|
|
}
|
|
}
|