Skip to content

Instantly share code, notes, and snippets.

@grtjn
Created November 7, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grtjn/7c63cd2787dab8a1542a26d5ddbfe270 to your computer and use it in GitHub Desktop.
Save grtjn/7c63cd2787dab8a1542a26d5ddbfe270 to your computer and use it in GitHub Desktop.
Docker-gen JSON Export template
{
"Docker": {
"Name": "{{ .Docker.Name }}",
"NumContainers": {{ .Docker.NumContainers }},
"NumImages": {{ .Docker.NumImages }},
"Version": "{{ .Docker.Version }}",
"ApiVersion": "{{ .Docker.ApiVersion }}",
"GoVersion": "{{ .Docker.GoVersion }}",
"OperatingSystem": "{{ .Docker.OperatingSystem }}",
"Architecture": "{{ .Docker.Architecture }}",
"CurrentContainerID": "{{ .Docker.CurrentContainerID }}"
},
"Env": {
{{ range $key, $value := .Env }}
"{{ $key }}": "{{ $value }}",
{{ end }}
},
"RuntimeContainers": [
{{ range $index, $container := $ }}
{
"ID": "{{ $container.ID }}",
"Addresses": [
{{ range $index, $address := $container.Addresses }}
{
"IP": "{{ $address.IP }}",
"IP6LinkLocal": "{{ $address.IP6LinkLocal }}",
"IP6Global": "{{ $address.IP6Global }}",
"Port": "{{ $address.Port }}",
"HostPort": "{{ $address.HostPort }}",
"Proto": "{{ $address.Proto }}",
"HostIP": "{{ $address.HostIP }}"
},
{{ end }}
],
"Networks": [
{{ range $index, $network := $container.Networks }}
{
"IP": "{{ $network.IP }}",
"Name": "{{ $network.Name }}",
"Gateway": "{{ $network.Gateway }}",
"EndpointID": "{{ $network.EndpointID }}",
"IPv6Gateway": "{{ $network.IPv6Gateway }}",
"GlobalIPv6Address": "{{ $network.GlobalIPv6Address }}",
"MacAddress": "{{ $network.MacAddress }}",
"GlobalIPv6PrefixLen": {{ $network.GlobalIPv6PrefixLen }},
"IPPrefixLen": {{ $network.IPPrefixLen }}
},
{{ end }}
],
"Gateway": "{{ $container.Gateway }}",
"Name": "{{ $container.Name }}",
"Hostname": "{{ $container.Hostname }}",
"Image": {
"Registry": "{{ $container.Image.Registry }}",
"Repository": "{{ $container.Image.Repository }}",
"Tag": "{{ $container.Image.Tag }}"
},
"Env": {
{{ range $key, $value := $container.Env }}
"{{ $key }}": "{{ $value }}",
{{ end }}
},
"Volumes": {
{{ range $key, $volume := $container.Volumes }}
"{{ $key }}": {
"Path": "{{ $volume.Path }}",
"HostPath": "{{ $volume.HostPath }}",
"ReadWrite": {{ $volume.ReadWrite }}
},
{{ end }}
},
"Node": {
"ID": "{{ $container.Node.ID }}",
"Name": "{{ $container.Node.Name }}",
{{ $address := $container.Node.Address }}
"Address": {
"IP": "{{ $address.IP }}",
"IP6LinkLocal": "{{ $address.IP6LinkLocal }}",
"IP6Global": "{{ $address.IP6Global }}",
"Port": "{{ $address.Port }}",
"HostPort": "{{ $address.HostPort }}",
"Proto": "{{ $address.Proto }}",
"HostIP": "{{ $address.HostIP }}"
}
},
"Labels": {
{{ range $key, $value := $container.Labels }}
"{{ $key }}": "{{ $value }}",
{{ end }}
},
"IP": "{{ $container.IP }}",
"IP6LinkLocal": "{{ $container.IP6LinkLocal }}",
"IP6Global": "{{ $container.IP6Global }}",
"Mounts": [
{{ range $index, $mount := $container.Mounts }}
{
"Name": "{{ $mount.Name }}",
"Source": "{{ $mount.Source }}",
"Destination": "{{ $mount.Destination }}",
"Driver": "{{ $mount.Driver }}",
"Mode": "{{ $mount.Mode }}",
"RW": {{ $mount.RW }}
},
{{ end }}
],
"State": {
"Running": {{ $container.State.Running }}
}
},
{{ end }}
]
}
@grtjn
Copy link
Author

grtjn commented Nov 7, 2020

Some dangling comma's I couldn't easily get rid of, and particularly .Env keys/values might not be escaped as should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment