Skip to content

Instantly share code, notes, and snippets.

@morsik
Created December 28, 2017 11:27
Show Gist options
  • Save morsik/0d58120c43c71e52b530eced1296129c to your computer and use it in GitHub Desktop.
Save morsik/0d58120c43c71e52b530eced1296129c to your computer and use it in GitHub Desktop.
Get all attributes for Docker API update command
def _get_old_attrs(service):
_s = service.attrs['Spec']
_t = _s['TaskTemplate']
_c = _t['ContainerSpec']
return {
'image': _c['Image'],
#command (list of str or str) – Command to run.
#args (list of str) – Arguments to the command.
'constraints': _t['Placement'].get('Constraints'),
#container_labels (dict) – Labels to apply to the container.
#endpoint_spec (EndpointSpec) – Properties that can be configured to access and load balance a service. Default: None.
'env': _c['Env'],
#hostname (string) – Hostname to set on the container.
'labels': _s['Labels'],
#log_driver (str) – Log driver to use for containers.
#log_driver_options (dict) – Log driver options.
'mode': _s['Mode'],
'mounts': ["{Source}:{Target}:rw".format(**x) for x in _c['Mounts']],
'name': _s['Name'],
'networks': ["{Target}".format(**x) for x in _s['Networks']],
#resources (Resources) – Resource limits and reservations.
#restart_policy (RestartPolicy) – Restart policy for containers.
#secrets (list of docker.types.SecretReference) – List of secrets accessible to containers for this service.
#stop_grace_period (int) – Amount of time to wait for containers to terminate before forcefully killing them.
#update_config (UpdateConfig) – Specification for the update strategy of the service. Default: None
#user (str) – User to run commands as.
#workdir (str) – Working directory for commands to run.
#tty (boolean) – Whether a pseudo-TTY should be allocated.
#groups (list) – A list of additional groups that the container process will run as.
#open_stdin (boolean) – Open stdin
#read_only (boolean) – Mount the container’s root filesystem as read only.
#stop_signal (string) – Set signal to stop the service’s containers
#healthcheck (Healthcheck) – Healthcheck configuration for this service.
#hosts (dict) – A set of host to IP mappings to add to the container’s hosts file.
#dns_config (DNSConfig) – Specification for DNS related configurations in resolver configuration file.
#configs (list) – List of ConfigReference that will be exposed to the service.
#privileges (Privileges) – Security options for the service’s containers.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment