How to do blurry search key name recursively in jq - jq

I don't like the original inspect method to search specific field on Docker, so I use jq to find the config I want, for example:
docker inspect test | jq '.[].NetworkSettings
docker inspect test | jq '.. | .NetworkSettings? | objects'
both scripts can get the results:
{
"Bridge": "",
"SandboxID": "4951989910db53c8bb8368add9ddcdf0e69cd14a9ff09ef95402850f24c5de08",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/4951989910db",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"test_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"f3df83d51385",
"test"
],
"NetworkID": "4b09f5c3a82cb7c9770efec1fc818eb071cf707bd60ec96202664d5282d73b6c",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
but is base on I totally type the config name NetworkSettings correctly, is there a way to do blurry search key recursively and case insensitive by jq? like docker inspect test | jq '.. | search(. | match("network";"i") | objects', it won't work, just an example.

With this def:
def blurry($f):
($f | ascii_upcase) as $ucf
| to_entries[]
| select((.key|ascii_upcase) == $ucf)
| .value;
you could write:
.. | blurry("NetworkSettings")? | objects
Blurrier
Blurriness having many shades, you could go further, e.g.:
def veryBlurry($f):
($f | ascii_upcase) as $ucf
| to_entries[]
| select(.key | ascii_upcase | index($ucf))
| .value;
You could continue along this path, e.g. using regular expressions.

Related

Parsing json file with jq from HPE iLO

I have a json file pulled from an HPE iLO interface with the snmp configuration. It looks like:
[
{
"Comments": {
"BIOSDate": "01/23/2021",
"BIOSFamily": "U30",
"Manufacturer": "HPE",
"Model": "ProLiant DL380 Gen10",
"SerialNumber": "5UNESX378",
"iLOVersion": "iLO 5 v2.65"
}
},
{
"#HpeiLOSnmpService.v2_3_0.HpeiLOSnmpService": {
"/redfish/v1/Managers/1/SnmpService/": {
"#odata.context": "/redfish/v1/$metadata#HpeiLOSnmpService.HpeIloSnmpService",
"#odata.id": "/redfish/v1/Managers/1/SnmpService",
"Actions": {
"#HpeIloSnmpService.SendSNMPTestAlert": {
"target": "/redfish/v1/Managers/1/SnmpService/Actions/HpeILOSnmpService.SendSNMPTestAlert/"
}
},
"AlertDestinationAssociations": [
{
"SNMPAlertProtocol": "SNMPv3Trap",
"SecurityName": null
}
],
"AlertDestinations": [
"1.2.3.4",
"5.6.7.8",
null,
null
],
"AlertsEnabled": true,
"Name": "SnmpService"
},
"PeriodicHSATrapConfig": "Disabled",
"ReadCommunities": [
"",
"",
""
],
"Role": "",
"RoleDetail": "",
"SNMPAlertDestinations": {
"#odata.id": "/redfish/v1/Managers/1/SnmpService/SNMPAlertDestinations/"
},
"SNMPUsers": {
"#odata.id": "/redfish/v1/Managers/1/SnmpService/SNMPUsers/"
},
"SNMPv1Enabled": false,
"SNMPv3EngineID": "0x8920000000E3028329E002033",
"SNMPv3InformRetryAttempt": 2,
"SNMPv3InformRetryIntervalSeconds": 15,
"Status": {
"State": "Enabled"
},
"TrapCommunities": [
"",
"",
"",
"",
"",
"",
""
],
"TrapSourceHostname": "Manager",
"Users": [
{
"AuthProtocol": "MD5",
"PrivacyProtocol": "DES",
"SecurityName": "",
"UserEngineID": null
},
{
"AuthProtocol": "MD5",
"PrivacyProtocol": "DES",
"SecurityName": "",
"UserEngineID": null
},
{
"AuthProtocol": "SHA",
"PrivacyProtocol": "AES",
"SecurityName": "oneview_4849283d97929392",
"UserEngineID": null
},
{
"AuthProtocol": "MD5",
"PrivacyProtocol": "DES",
"SecurityName": "",
"UserEngineID": null
}
]
}
}
]
I want to select an element in the Users array that has SecurityName set to "" and change that element. I don't need the Comments portion. So, I try to select the section starting with #HpeiLOSnmpService.v2_3_0.HpeiLOSnmpService with:
jq -r '.[] | .#HpeiLOSnmpService.v2_3_0.HpeiLOSnmpService' snmp.json
but it gives me everything without the enclosing array. Anyone have a suggestion?
Thanks!
# starts a comment and your jq program degenerates to .[]|. which is identical to the program .[] (|. is a no-op/the identity filter). This program will simply select all values from the input.
You must quote certain characters, such as #, when they are part of propery names. The following will work with your JSON file:
jq -r '.[] | ."#HpeiLOSnmpService".v2_3_0.HpeiLOSnmpService'
Thanks. Using the quotes around the key with a '#' works. Ultimately, selecting the SecurityName that was unset was done with:
jq -r '.Users[] | select (.SecurityName == "") | {"AuthProtocol":.AuthProtocol,"PrivacyProtocol":.PrivacyProtocol,"SecurityName":.SecurityName,"UserEngineID":.UserEngineID}'

jq query to pull values from json file to create a listing

Given this input small sample:
{
"_format_version": "1.1",
"_workspace": "test",
"services": [
{
"connect_timeout": 60000,
"host": "host-name-test.com",
"name": "name-of-service",
"path": "/test/oauthpass",
"port": 777,
"protocol": "http",
"read_timeout": 1000,
"retries": 1,
"write_timeout": 1000,
"routes": [
{
"hosts": [
"Google.com"
],
"name": "com.testing.active.oauth",
"methods": [
"POST"
],
"paths": [
"/vendors/otest/pass/?$"
],
"path_handling": "v8",
"preserve_host": false,
"protocols": [
"https"
],
"regex_priority": 0,
"strip_path": true,
"https_redirect_status_code": 426,
"request_buffering": true,
"response_buffering": true
}
]
}
}
trying to get a listing from the data pulling certain values like the listing below:
host-name-test.com, Google.com, POST, HTTPS
the command that I have working so far is
cat /tmp/petecar.json | jq -r ' .services[] | .routes[] | ( .hosts[] + "/" + .paths[]) ' | more
but I can't access the values under services, please provide some sample on how to get the values
routes has an array value and as such cannot be concatenated with a string. You can use join to turn that array into a single string:
jq -r '.services[] | .host + " " + (.routes[].hosts | join(","))'
Output:
host-name-test.com Google.com
Alternatively, using string interpolation) which will automatically serialize any values into their string representation:
jq -r '.services[] | "\(.host) \(.routes[].hosts)"'
Output:
host-name-test.com ["Google.com"]
join and string interpolation can be combined, giving you the identical output of the first command:
jq -r '.services[] | "\(.host) \(.routes[].hosts|join(","))"'

How do I iterate through array in Kusto?

I need to iterate through managed data disks in Azure Resource Graph Explorer (https://preview.portal.azure.com/). My query is below but it returns JSON array, I need to extract name of disk and type of storage account which is being used (sample JSON return is below). So I'd like to see on screen grouping by machine name, disk name and then storage account type. My current query is below but obviously it does not work due to return of JSON
where type =~ 'Microsoft.Compute/virtualmachines' |
extend disks = properties.storageProfile.dataDisks |
project name, disks
Same JSON output
[
{
"name": "COMP02_DDisk1",
"createOption": "Attach",
"diskSizeGB": 400,
"managedDisk": {
"id": "/subscriptions/5f5c5be9-77d4db790171/resourceGroups/BRAZILSOUTHDB/providers/Microsoft.Compute/disks/COMP02_DDisk1",
"storageAccountType": "Premium_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 0,
"writeAcceleratorEnabled": false
},
{
"name": "COMP02_DDisk2",
"createOption": "Attach",
"diskSizeGB": 400,
"managedDisk": {
"id": "/subscriptions/5f5c5be9-77d4db790171/resourceGroups/BRAZILSOUTHDB/providers/Microsoft.Compute/disks/COMP02_DDisk2",
"storageAccountType": "Premium_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 1,
"writeAcceleratorEnabled": false
}
]
in such cases, it's usually helpful to use mv-expand to expand the array and then apply the dynamic-property accessors foreach record.
https://learn.microsoft.com/en-us/azure/kusto/query/mvexpandoperator
example:
print d = dynamic([
{
"name": "COMP02_DDisk1",
"createOption": "Attach",
"diskSizeGB": 400,
"managedDisk": {
"id": "/subscriptions/5f5c5be9-77d4db790171/resourceGroups/BRAZILSOUTHDB/providers/Microsoft.Compute/disks/COMP02_DDisk1",
"storageAccountType": "Premium_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 0,
"writeAcceleratorEnabled": false
},
{
"name": "COMP02_DDisk2",
"createOption": "Attach",
"diskSizeGB": 400,
"managedDisk": {
"id": "/subscriptions/5f5c5be9-77d4db790171/resourceGroups/BRAZILSOUTHDB/providers/Microsoft.Compute/disks/COMP02_DDisk2",
"storageAccountType": "Premium_LRS"
},
"caching": "None",
"toBeDetached": false,
"lun": 1,
"writeAcceleratorEnabled": false
}
])
| mv-expand d
| project d.name, d.managedDisk.storageAccountType
which will output:
| d_name | d_managedDisk_storageAccountType |
|---------------|----------------------------------|
| COMP02_DDisk1 | Premium_LRS |
| COMP02_DDisk2 | Premium_LRS |
Hope you are doing good .
You can try this way also, First i found networksecuritygroups from entire collection and later filtered defaultSecurityRules which is again an array.
After collecting it using mvexpand in local variable rules you should be able to fetch the desired after applying.
where type =~ "microsoft.network/networksecuritygroups"
| mvexpand rules = properties.defaultSecurityRules
| where rules.properties.destinationAddressPrefix =~ "*"
You can also refer given below link and wish it will help you also.

Docker expose service to achieve dockerized wordpress multisite

I have been trying to enable Wordpress multisite network for a dockerized Wordpress application.
The application can be accessed via IP and port like this:
http://0.0.0.0:8282
When I enable WP_ALLOW_MULTISITE in wp-config.php I get the error from Wordpress that I can not use domain names with port e.g. :8282
in this particular case.
So I was looking for a way how to expose some domain name from Docker container, instead of 0.0.0.0:8282
I found this example:
https://www.theimpossiblecode.com/blog/docker-wordpress-multisite-with-subdomains/
And I went over the example to make it work, as it is described. Then I intend to look for a way how to implement it for my particular application.
The problem:
I started by exposing a service, described on linked page:
https://www.theimpossiblecode.com/blog/docker-expose-service/
I used the enclosed docker-compose.yml from that page, and when I run
$ docker-compose up -d
the containers appear to be working:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
edaeb215b3eb wordpress:latest "docker-entrypoint.s…" 34 minutes ago Up 34 minutes 80/tcp dockwpress_wordpress_1
5dc6fa8480c6 mysql:5.7 "docker-entrypoint.s…" 34 minutes ago Up 34 minutes 3306/tcp, 33060/tcp dockwpress_db_1
But, I can't access: http://dockerwp and $ dig dockerwp yields this:
; <<>> DiG 9.10.6 <<>> dockerwp
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 23290
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;dockerwp. IN A
;; Query time: 34 msec
;; SERVER: 10.11.137.100#53(10.11.137.100)
;; WHEN: Thu Dec 13 17:05:34 GMT 2018
;; MSG SIZE rcvd: 37
When inspecting the container I see that the dockerwp domain name has been exposed (the "com.theimpossiblecode.expose.host": "dockerwp" line).
$ docker inspect edaeb215b3eb
[
{
"Id": "edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb",
"Created": "2018-12-13T16:28:55.122420503Z",
"Path": "docker-entrypoint.sh",
"Args": [
"apache2-foreground"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 10823,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-12-13T16:28:55.733061919Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:55b751a7663f6d4fdd0d5f3785b0a846868147dceff99dd169f0a33214be3452",
"ResolvConfPath": "/var/lib/docker/containers/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb/hostname",
"HostsPath": "/var/lib/docker/containers/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb/hosts",
"LogPath": "/var/lib/docker/containers/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb-json.log",
"Name": "/dockwpress_wordpress_1",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "dockwpress_default",
"PortBindings": {},
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/8ab6c3eb7bb9e80de85a5c39849775d339d9466c182b236eca411f1cb32d7f29-init/diff:/var/lib/docker/overlay2/44b78d4977abf7cab796267c277db0e31efd5190f917dce4167237070fb0317e/diff:/var/lib/docker/overlay2/1d3fb40ede0d5e2626d4d1ea19e93cb15702a7bcb569bf2811e652d25409623f/diff:/var/lib/docker/overlay2/f59d3c961f65e7ad1297bf888ed04905dff998a31a5796c7c903a8f854749a3b/diff:/var/lib/docker/overlay2/af222f8ba1e9c68b16935d08a0325ec8ff173a2944082e8d3e568a2c738d591f/diff:/var/lib/docker/overlay2/1bac18c6dc58c3ebd7982dd3ccdfb7fdbc4037de6277c20d84baba95babaf4c1/diff:/var/lib/docker/overlay2/32df749d5027d957ebba6167f8715bbbc117c0787c8d5849f318391d427dfcaf/diff:/var/lib/docker/overlay2/e6927c13204369a44dc8f4de4a8ab8a3307b0f8fa5eb758a565a67a1b923451a/diff:/var/lib/docker/overlay2/a6299eec8f02b0c2a190a9646b7576209e0e39f6bae1d81f543daaabe0dd89d4/diff:/var/lib/docker/overlay2/d0e4d7ff78e7373c4f3885e8cad840617764e9a803bda6eb30e681cdc910bf51/diff:/var/lib/docker/overlay2/fc48c85e773fd6d0e52b4a84116224d2ee0a396a470df44b009fb56ef8276704/diff:/var/lib/docker/overlay2/77aea6e322140a30aff363c97e67bad3f2ab78f301ebdadc89275f9e1e86ad0d/diff:/var/lib/docker/overlay2/fec4aae10fb644332df8a1c286c9635a1ae85f2d9aaf8838ae08b7e6f3268a8d/diff:/var/lib/docker/overlay2/41bfdb4f1afa0d88890af4deb33c403e5816a6b2823d3a9ed5fb19079b4faa9b/diff:/var/lib/docker/overlay2/5aa746815fbdaeedc7a727ca34072f1183af9bc0ba7908b480e37ee9f5884761/diff:/var/lib/docker/overlay2/aa6c25c7e61f3512a55f69ed5c39f492b80a500704bdc9a91af8ff811f74f58d/diff:/var/lib/docker/overlay2/41c27f1bb64072e7deebc7eee4b46f3c38b63e2bc56ebfaf9c88159f1d6c67c2/diff:/var/lib/docker/overlay2/512ece5edecc822e72e5d939d75339e02582696dbc5205f756516c4b635ff9d3/diff:/var/lib/docker/overlay2/7bd7bb38c22c9ee4dd2c38d2c32ac12bbb2034c759879a26b73b351ac7a5e26e/diff:/var/lib/docker/overlay2/602c7d2fa85ca8e4945236214ffb852abcfd716f5626d273b510b470d7878d02/diff",
"MergedDir": "/var/lib/docker/overlay2/8ab6c3eb7bb9e80de85a5c39849775d339d9466c182b236eca411f1cb32d7f29/merged",
"UpperDir": "/var/lib/docker/overlay2/8ab6c3eb7bb9e80de85a5c39849775d339d9466c182b236eca411f1cb32d7f29/diff",
"WorkDir": "/var/lib/docker/overlay2/8ab6c3eb7bb9e80de85a5c39849775d339d9466c182b236eca411f1cb32d7f29/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "volume",
"Name": "bd2706aae2dbddaa65a85e77ca89efc3844dc600f72e1e8b1f9b6803cbb8459c",
"Source": "/var/lib/docker/volumes/bd2706aae2dbddaa65a85e77ca89efc3844dc600f72e1e8b1f9b6803cbb8459c/_data",
"Destination": "/var/www/html",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "edaeb215b3eb",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"WORDPRESS_DB_HOST=db:3306",
"WORDPRESS_DB_USER=wordpress",
"WORDPRESS_DB_PASSWORD=wordpress",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"PHPIZE_DEPS=autoconf \t\tdpkg-dev \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c",
"PHP_INI_DIR=/usr/local/etc/php",
"APACHE_CONFDIR=/etc/apache2",
"APACHE_ENVVARS=/etc/apache2/envvars",
"PHP_EXTRA_BUILD_DEPS=apache2-dev",
"PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2 --disable-cgi",
"PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2",
"PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2",
"PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie",
"GPG_KEYS=1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F",
"PHP_VERSION=7.2.13",
"PHP_URL=https://secure.php.net/get/php-7.2.13.tar.xz/from/this/mirror",
"PHP_ASC_URL=https://secure.php.net/get/php-7.2.13.tar.xz.asc/from/this/mirror",
"PHP_SHA256=14b0429abdb46b65c843e5882c9a8c46b31dfbf279c747293b8ab950c2644a4b",
"PHP_MD5=",
"WORDPRESS_VERSION=5.0",
"WORDPRESS_SHA1=67758958f14c1dcefe37ce6558d470a4e142893b"
],
"Cmd": [
"apache2-foreground"
],
"ArgsEscaped": true,
"Image": "wordpress:latest",
"Volumes": {
"/var/www/html": {}
},
"WorkingDir": "/var/www/html",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "c8ce0ffef4cef318c23c0e6142dcb5b42a97df29507969c72a99e95b3343f0ec",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "dockwpress",
"com.docker.compose.service": "wordpress",
"com.docker.compose.version": "1.23.2",
"com.theimpossiblecode.expose.host": "dockerwp"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "83bdba7bf688685fa842ab8c1c38a53f26af088c2fd1063492ae55cb73cc6cd6",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": null
},
"SandboxKey": "/var/run/docker/netns/83bdba7bf688",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"dockwpress_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"wordpress",
"edaeb215b3eb"
],
"NetworkID": "6b7d8cc32a6e208f379a8ecfdf88910c85c575e284ad2e3632520fe86ec937ad",
"EndpointID": "a7d991d525463bb83b2eedb78baf59358d8a543f3b5244034eaea6cce99ef525",
"Gateway": "172.28.0.1",
"IPAddress": "172.28.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:1c:00:03",
"DriverOpts": null
}
}
}
}
]
What could be causing the http://dockerwp to be not accessible?
Browser shows this error:
This site can’t be reached dockerwp’s server IP address could not be found.
Did you mean http://docker.com/?
Search Google for docker wp
ERR_NAME_NOT_RESOLVED
Thank you.
dockerwp in http://dockerwp is a domain name that does not exist.
You example is only valid if you deploy your wp site to their platform which will give you a subdomain called "dockerwp". The label om.theimpossiblecode.expose.host is read by their reverse proxy to create this effect.
In conclusion you can't set hostname with this configuration. You will be better off just access your site with localhost:port.
The solution is to use Nginx proxy server e.g. https://github.com/jwilder/nginx-proxy
So by using two containers, one is the proxy and another is Wordpress application docker container, you can add vhost entries to /etc/hosts as 127.0.0.1 devwebsite.local for any of required virtual hosts. Those have to be configured for the WP container, the VIRTUAL_HOST env. variable.
Here is the example:https://github.com/djuro/dockerMultisiteWordpress, the Dockerfile and docker-compose.yml in particular.
I used 2 more containers, for database and GUI db tool (Adminer), but those are both optional.

JQ Cross reference or how to replace one value with another part of the input

I want to parse terraform.tfstate (where openstack provider is used), to return instance name and it's internal + floating IP (if assigned).
First select what we are interested in:
jq -r '.modules?[]|.resources[]?|select(.type == "openstack_compute_floatingip_v2", .type == "openstack_compute_instance_v2")' < terraform.tfstate
For simplicity, pre-parsed example with the above part (one FIP and one instance):
{
"type": "openstack_compute_floatingip_v2",
"depends_on": [
"openstack_networking_router_interface_v2.management"
],
"primary": {
"id": "48b039fc-a9fa-4672-934a-32d6d267f280",
"attributes": {
"address": "209.66.89.143",
"fixed_ip": "10.10.10.5",
"id": "48b039fc-a9fa-4672-934a-32d6d267f280",
"instance_id": "597e75e8-834d-4f05-8408-e2e6e733577e",
"pool": "public",
"region": "RegionOne"
},
"meta": {},
"tainted": false
},
"deposed": [],
"provider": "provider.openstack"
}
{
"type": "openstack_compute_instance_v2",
"depends_on": [
"openstack_compute_floatingip_v2.management",
"openstack_compute_secgroup_v2.ssh_only",
"openstack_networking_network_v2.management"
],
"primary": {
"id": "597e75e8-834d-4f05-8408-e2e6e733577e",
"attributes": {
"access_ip_v4": "10.10.10.5",
"access_ip_v6": "",
"all_metadata.%": "1",
"all_metadata.habitat": "sup",
"availability_zone": "nova",
"flavor_id": "eb36e84e-17c1-42ab-b359-4380f6f524ae",
"flavor_name": "m1.large",
"force_delete": "false",
"id": "597e75e8-834d-4f05-8408-e2e6e733577e",
"image_id": "c574aeed-e47c-4fb7-9da0-75550b76ee56",
"image_name": "ubuntu-16.04",
"key_pair": "vault-etcd_test_tf",
"metadata.%": "1",
"metadata.habitat": "sup",
"name": "ctl01",
"network.#": "1",
"network.0.access_network": "false",
"network.0.fixed_ip_v4": "10.10.10.5",
"network.0.fixed_ip_v6": "",
"network.0.floating_ip": "",
"network.0.mac": "02:c6:61:f9:ee:7e",
"network.0.name": "management",
"network.0.port": "",
"network.0.uuid": "f2468669-e321-4eb4-9ede-003e362a8988",
"region": "RegionOne",
"security_groups.#": "1",
"security_groups.1845949017": "vault-etcd_test_ssh_only",
"stop_before_destroy": "false"
},
"meta": {
"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0": {
"create": 1800000000000,
"delete": 1800000000000,
"update": 1800000000000
}
},
"tainted": false
},
"deposed": [],
"provider": "provider.openstack"
}
Required is to take from "type": "openstack_compute_floatingip_v2" replace .primary.attributes.address and .fixed_ip and from corresponding .instance_id the .name.
So, sth like:
{"address": "209.66.89.143",
"fixed_ip": "10.10.10.5",
"name": "ctl01"}
Well, I came with an idea while using walk, but miss how to actually assign the proper value from corresponding instance id:
jq -r "$(cat floating.jq)" terraform.tfstate
floating.jq:
def walk(f):
. as $in
| if type == "object" then
reduce keys[] as $key
( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f
elif type == "array" then map( walk(f) ) | f
else f
end;
.modules?[]|.resources[]?|select(.type ==
"openstack_compute_floatingip_v2", .type ==
"openstack_compute_instance_v2")|
.primary|walk( if type == "object" and .attributes.address then
.attributes.instance_id |= "REFERRED VALUE HERE") else . end)
Let's assume the two related objects are in a file named two.json. Then one way to merge the information from both objects is using the -s command-line option, e.g.
jq -s '
(.[0].primary.attributes | {address, fixed_ip})
+ {name: .[1].primary.attributes.name}' two.json
Output
With your example input, the output would be:
{
"address": "209.66.89.143",
"fixed_ip": "10.10.10.5",
"name": "ctl01"
}

Resources