Service
Handle
Represents a Docker Compose service definition.
type Service interface{}50 members
Properties
property
CapAdd *List[string]get · setSpecifies a list of Linux capabilities to add to the container.
CapAdd() *List[string]SetCapAdd(value *List[string]) Serviceproperty
CapDrop *List[string]get · setRepresents a list of Linux capabilities to be dropped from the service's container. This property can be used to restrict specific capabilities that the container should not have access to, enhancing security by implementing the principle of least privilege.
CapDrop() *List[string]SetCapDrop(value *List[string]) Serviceproperty
CgroupParent *stringget · setGets or sets the parent Cgroup for the container. This property defines the name of the Cgroup under which the container's resource constraints are managed.
CgroupParent() (*string, error)SetCgroupParent(value *string) Serviceproperty
Command*List[string]get · setRepresents the command to override the default command specified in the image's Dockerfile. This property allows specifying how the container should run by defining an executable and its arguments.
Command() *List[string]SetCommand(value *List[string]) Serviceproperty
Configs*List[ConfigReference] get · setRepresents a collection of configuration references associated with the service. Each configuration is defined as a reference to an external configuration resource, which can be used to manage application configurations.
Configs() *List[ConfigReference]SetConfigs(value *List[ConfigReference]) Serviceproperty
ContainerName *stringget · setSpecifies the name of the container to be used. This property maps to the "container_name" field in a Docker Compose file. If set, the container will have the specified name; otherwise, a name will be automatically generated.
ContainerName() (*string, error)SetContainerName(value *string) Serviceproperty
DependsOn *Dict[string, ServiceDependency] get · setSpecifies a list of services that this service depends on. The dependencies are expressed as service names with optional conditions. Supported conditions are: "service_started", "service_healthy", "service_completed_successfully" This property defines the order in which services should be started, ensuring that the specified services are initialized before the current service.
DependsOn() *Dict[string, ServiceDependency]SetDependsOn(value *Dict[string, ServiceDependency]) Serviceproperty
Devices*List[string]get · setRepresents a collection of device mappings for the service container. This property defines the host-to-container device paths in Docker.
Devices() *List[string]SetDevices(value *List[string]) Serviceproperty
Dns*List[string]get · setGets or sets a list of custom DNS server IP addresses to be used by the service container.
Dns() *List[string]SetDns(value *List[string]) Serviceproperty
DnsSearch *List[string]get · setSpecifies the domain search options for the service's container. This property allows you to define one or more domain search suffixes that will be appended to unqualified DNS queries performed by the container. Typically used to configure how DNS resolution should behave in specific network setups.
DnsSearch() *List[string]SetDnsSearch(value *List[string]) Serviceproperty
DomainName *stringget · setRepresents the domain name of a service container.
DomainName() (*string, error)SetDomainName(value *string) Serviceproperty
Entrypoint*List[string]get · setSpecifies the entrypoint to be used for the container. This property allows overriding the default entrypoint of the image and defines the executable or command that is run when the container starts.
Entrypoint() *List[string]SetEntrypoint(value *List[string]) Serviceproperty
EnvFile *List[string]get · setRepresents a collection of paths to environment variable files used by the service. These files contain key-value pairs of environment variables that will be loaded and applied to the service configuration at runtime.
EnvFile() *List[string]SetEnvFile(value *List[string]) Serviceproperty
Environment*Dict[string, string] get · setRepresents a collection of environment variables for the service container.
Environment() *Dict[string, string]SetEnvironment(value *Dict[string, string]) Serviceproperty
Expose*List[string]get · setGets or sets a list of ports to expose from the container without publishing them to the host machine. This property defines internal ports that the container makes available to linked services or other containers within the same network, but these ports are not accessible from outside the container’s network.
Expose() *List[string]SetExpose(value *List[string]) Serviceproperty
ExternalLinks *List[string]get · setGets or sets the external links for the service. External links are references to services defined outside the current Docker Compose file, enabling communication with containers in other projects or environments.
ExternalLinks() *List[string]SetExternalLinks(value *List[string]) Serviceproperty
ExtraHosts *Dict[string, string] get · setRepresents additional hostname-to-IP mappings for the service. These mappings allow you to manually define hostnames and corresponding IP addresses, effectively augmenting the DNS resolution for the service's containers.
ExtraHosts() *Dict[string, string]SetExtraHosts(value *Dict[string, string]) Serviceproperty
GroupAdd *List[string]get · setGets or sets a list of additional group IDs to add to the container's process. This allows the container to have access to resources or permissions associated with the specified groups.
GroupAdd() *List[string]SetGroupAdd(value *List[string]) Serviceproperty
Hostname*stringget · setGets or sets the hostname for the service container. This defines the hostname that will be assigned to the container and can be used for network identification within the container's network.
Hostname() (*string, error)SetHostname(value *string) Serviceproperty
Image*stringget · setSpecifies the Docker image to be used for the service.
Image() (*string, error)SetImage(value *string) Serviceproperty
Init*boolget · setIndicates whether the init binary should be used as the container's init process. When set to true, the init process is used to ensure proper reaping of zombie processes and signal forwarding inside the container.
Init() (*bool, error)SetInit(value *bool) Serviceproperty
Ipc*stringget · setGets or sets the IPC (Inter-Process Communication) mode for the service. This property determines how IPC namespaces are shared between containers and the host. It can be set to values such as "none", "host", or a specific container ID to share IPC resources with.
Ipc() (*string, error)SetIpc(value *string) Serviceproperty
Isolation*stringget · setSpecifies the isolation mode for the container. This property determines the level of isolation between the container and the host system. Common values include "default", "process", or "hyperv", and the supported options may depend on the container runtime or the platform being used.
Isolation() (*string, error)SetIsolation(value *string) Serviceproperty
Labels*Dict[string, string] get · setRepresents a set of metadata labels for the service. These key-value pairs can be used to organize and identify objects within the service configuration.
Labels() *Dict[string, string]SetLabels(value *Dict[string, string]) Serviceproperty
Links*List[string]get · setRepresents a service definition in a Docker Compose configuration file.
Links() *List[string]SetLinks(value *List[string]) Serviceproperty
MacAddress *stringget · setSpecifies a custom MAC (Media Access Control) address for the container's network interface.
MacAddress() (*string, error)SetMacAddress(value *string) Serviceproperty
Namestringget · setGets or sets the name of the Docker Compose member.
Name() (string, error)SetName(value string) Serviceproperty
NetworkMode *stringget · setSpecifies the network mode to be used for the container. This property determines the networking configuration, such as whether the container shares the network stack with the host, uses a predefined network, or operates in isolation. The value is typically a string that matches a network mode supported by the environment, such as 'bridge', 'host', 'none', or a custom network name.
NetworkMode() (*string, error)SetNetworkMode(value *string) Serviceproperty
Networks*List[string]get · setDefines the collection of networks that the service is connected to. This property specifies the names of the networks the service should be attached to. Each entry in this list represents a network defined in the Docker Compose file or an externally defined network. Connecting a service to one or more networks allows inter-service communication across those networks, as well as communication with external systems configured on those same networks. If no network is specified, the service is connected to the default network that is automatically created by Docker Compose for the project unless
network_mode is set to another value.Networks() *List[string]SetNetworks(value *List[string]) Serviceproperty
Pid*stringget · setGets or sets the PID (Process Identifier) namespace configuration for the container. This property determines whether the container shares the PID namespace with the host or other containers, allowing process visibility and signal sending between them.
Pid() (*string, error)SetPid(value *string) Serviceproperty
Ports*List[string]get · setRepresents a collection of port mappings for the service. Each mapping specifies how a container port is bound to a host port.
Ports() *List[string]SetPorts(value *List[string]) Serviceproperty
Privileged*boolget · setIndicates whether the container should run in privileged mode. When set to true, the container is granted extended Linux capabilities and device access.
Privileged() (*bool, error)SetPrivileged(value *bool) Serviceproperty
Profiles*List[string]get · setDefines a list of profiles associated with the service. Profiles allow grouping of services and provide the ability to selectively enable services based on specified runtime profiles. If no profiles are specified, the service will be active in all configurations.
Profiles() *List[string]SetProfiles(value *List[string]) Serviceproperty
PullPolicy *stringget · setSpecifies the policy for pulling the Docker image.
PullPolicy() (*string, error)SetPullPolicy(value *string) Serviceproperty
ReadOnly *boolget · setDefines whether the service containers should be run in read-only mode. If set to true, the containers will have a read-only file system, limiting write operations to specific directories defined by writable mounts or tempfs.
ReadOnly() (*bool, error)SetReadOnly(value *bool) Serviceproperty
Restart*stringget · setSpecifies the restart policy for the container. This property determines how the container should behave in case of a crash or termination. Common values include "no", "always", "on-failure", and "unless-stopped".
Restart() (*string, error)SetRestart(value *string) Serviceproperty
Secrets*List[SecretReference] get · setRepresents a collection of secret references used by the service.
Secrets() *List[SecretReference]SetSecrets(value *List[SecretReference]) Serviceproperty
SecurityOpt *List[string]get · setRepresents a list of security options that can be applied to the container. This is used to configure security-related settings specific to the container such as SELinux labels or AppArmor profiles, providing fine-grained control over the container's security behavior.
SecurityOpt() *List[string]SetSecurityOpt(value *List[string]) Serviceproperty
ShmSize *stringget · setGets or sets the size of the
/dev/shm partition for the container.ShmSize() (*string, error)SetShmSize(value *string) Serviceproperty
StdinOpen *boolget · setIndicates whether standard input (stdin) should remain open and be attached to the service container, even if no terminal is connected.
StdinOpen() (*bool, error)SetStdinOpen(value *bool) Serviceproperty
StopGracePeriod *stringget · setGets or sets the stop grace period for the container. This specifies the amount of time to wait before forcing a container to stop after the stop or shutdown signal is sent. The value can be defined in a time duration format, such as "10s" for 10 seconds or "1m" for 1 minute.
StopGracePeriod() (*string, error)SetStopGracePeriod(value *string) Serviceproperty
StopSignal *stringget · setSpecifies the signal that will be used to stop the container. This property allows you to define a custom stop signal other than the default SIGTERM.
StopSignal() (*string, error)SetStopSignal(value *string) Serviceproperty
Sysctls*Dict[string, string] get · setRepresents a set of kernel parameters, specified as key-value pairs, that can be applied to the container at runtime. This property allows customization of specific Linux kernel settings (sysctl parameters) for the container, enabling fine-tuned control over its behavior. Common use cases include tuning network parameters or configuring shared memory limits. Note: Supported kernel parameters will vary based on the Docker daemon and the host system. Unsupported parameters will result in an error. Example: Use this property to set parameters like
net.ipv4.tcp_syncookies or net.core.somaxconn .Sysctls() *Dict[string, string]SetSysctls(value *Dict[string, string]) Serviceproperty
Tmpfs*List[string]get · setSpecifies a list of temporary file systems (tmpfs) to be mounted inside the container. Each entry represents a directory on the container's filesystem, mounted as a tmpfs, which resides in-memory and is typically used for ephemeral storage or caching purposes.
Tmpfs() *List[string]SetTmpfs(value *List[string]) Serviceproperty
Tty*boolget · setSpecifies whether a pseudo-TTY (teletypewriter) should be allocated for the container. When set to true, it enables the container to run with an interactive terminal session.
Tty() (*bool, error)SetTty(value *bool) Serviceproperty
Ulimits*Dict[string, Ulimit] get · setRepresents a collection of ulimit constraints for the service. Ulimits specify system resource limitations to be applied to the container, such as maximum number of open files or maximum stack size.
Ulimits() *Dict[string, Ulimit]SetUlimits(value *Dict[string, Ulimit]) Serviceproperty
User*stringget · setSpecifies the user that the container will run as. The value can be set to a numeric UID, a string for the username, or a combination of both (e.g., "UID:GID").
User() (*string, error)SetUser(value *string) Serviceproperty
Volumes*List[Volume]get · setDefines the list of volumes to be mounted into the service's container.
Volumes() *List[Volume]SetVolumes(value *List[Volume]) Serviceproperty
WorkingDir *stringget · setGets or sets the working directory of the container. Specifies the directory in which commands are run inside the container. Corresponds to the "working_dir" property in a Docker Compose file.
WorkingDir() (*string, error)SetWorkingDir(value *string) ServiceMethods
method
AddVolume Adds a volume mount to a generated Docker Compose service.
AddVolume( source string, target string, options ...*ServiceAddVolumeOptions,) ServiceParameters
sourcestringThe source volume name or host path.targetstringThe target path inside the container.options...*ServiceAddVolumeOptions Optional settings, described under Options.Options
Optional parameters are passed in a trailing options ...*ServiceAddVolumeOptions argument.
Type*stringThe Docker Compose volume type, such as volume or bind.IsReadOnly *boolA value indicating whether the volume is mounted as read-only.Configurefunc(obj Volume) callbackAn optional callback for further volume customization.Returns
ServiceThe updated Docker Compose service.
Returns a handle; failures surface later via Err().