How to access a mysql database that is into a Docker continer? - mysql

I'm working in a windows environment and I have my MySQL database into a Docker container, but how I should access from an external application?
Right now I'm just want to use a regular Java Class to test the connection but what address should I use? I've tried with the boot2docker ip, but that doesn't work. I've also tried with the ip that I got with the docker inspect command but I haven't got any result.
[
{
"Id": "ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16",
"Created": "2015-08-11T16:07:44.597618319Z",
"Path": "/entrypoint.sh",
"Args": [
"mysqld"
],
"State": {
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 2167,
"ExitCode": 0,
"Error": "",
"StartedAt": "2015-08-11T16:38:38.256276665Z",
"FinishedAt": "2015-08-11T16:38:08.508576127Z"
},
"Image": "a128139aadf282a10ec937a60010f837fa1b91dd367e05c7ca6197a84b3115b3",
"NetworkSettings": {
"Bridge": "",
"EndpointID": "a6e0a25891c065dc47b9dccb19c89e0ab7ee358a2b7cf947f6385bb47b99bac4",
"Gateway": "172.17.42.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"HairpinMode": false,
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:05",
"NetworkID": "5c8e21999516c552412027ab316d3a8d8d813952fb207c1de9ec38040895fc50",
"PortMapping": null,
"Ports": {
"3306/tcp": null
},
"SandboxKey": "/var/run/docker/netns/ee02d1e46305",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null
},
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16/resolv.conf",
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16/hostname",
"HostsPath": "/mnt/sda1/var/lib/docker/containers/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16/hosts",
"LogPath": "/mnt/sda1/var/lib/docker/containers/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16-json.log",
"Name": "/fluxtream",
"RestartCount": 0,
"Driver": "aufs",
"ExecDriver": "native-0.2",
"MountLabel": "",
"ProcessLabel": "",
"Volumes": {
"/var/lib/mysql": "/mnt/sda1/var/lib/docker/volumes/5a05900d9551d22235e51a7d03a7354156fce1bdea3e7378f52df8d33fee1f4f/_data"
},
"VolumesRW": {
"/var/lib/mysql": true
},
"AppArmorProfile": "",
"ExecIDs": [
"8fd70881d9cfed795dfb6850d513e54490432fd1e55e8bf8f6040f71cc1e7a4c",
"d3ca3e35de0222127c7e5da3e6ab45157cb06f5716c0c2bbfdc9a7096230786d",
"b75620585c02840a62169bc5adf0a5a80fa265194ac74136c54dc31cf9edd653",
"a61e680448ad796b1ad113776c5ba46f3b8a03f6601d843b005722748c9d5669"
],
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LxcConf": [],
"Memory": 0,
"MemorySwap": 0,
"CpuShares": 0,
"CpuPeriod": 0,
"CpusetCpus": "",
"CpusetMems": "",
"CpuQuota": 0,
"BlkioWeight": 0,
"OomKillDisable": false,
"Privileged": false,
"PortBindings": {},
"Links": null,
"PublishAllPorts": false,
"Dns": null,
"DnsSearch": null,
"ExtraHosts": null,
"VolumesFrom": null,
"Devices": [],
"NetworkMode": "bridge",
"IpcMode": "",
"PidMode": "",
"UTSMode": "",
"CapAdd": null,
"CapDrop": null,
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"SecurityOpt": null,
"ReadonlyRootfs": false,
"Ulimits": null,
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"CgroupParent": ""
},
"Config": {
"Hostname": "ee02d1e46305",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"PortSpecs": null,
"ExposedPorts": {
"3306/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"MYSQL_ROOT_PASSWORD=fluxtream",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"MYSQL_MAJOR=5.6",
"MYSQL_VERSION=5.6.26"
],
"Cmd": [
"mysqld"
],
"Image": "mysql:5.6.26",
"Volumes": {
"/var/lib/mysql": {}
},
"VolumeDriver": "",
"WorkingDir": "",
"Entrypoint": [
"/entrypoint.sh"
],
"NetworkDisabled": false,
"MacAddress": "",
"OnBuild": null,
"Labels": {}
}
}
]
My dev enviroment:
Windows 7 Pro
Docker 1.7.0
Boot2Docker-cli version 1.7.0
MySQL container 5.6.26

What worked for my is mapping the port when I created the container.
docker run --name YOUR_CONTAINER -p 3306:3306 -e MYSQL_ROOT_PASSWORD=YOUR_PASS -d mysql:5.6.26

Related

Azure Congnitive Service Skill not persisting custom skill value

I have create a custom skill for my Azure Cognitive Service. After creating the datasouce, index, indexer and running the indexer I can see that my function is being called and it is outputting the correct information, but when I search the index the field that is connected to the custom skill is empty.
This is my indexer definition:
{
"name": "idxdocs",
"description": null,
"dataSourceName": "dsdocs",
"skillsetName": "skillset-procuradores",
"targetIndexName": "customer-documents",
"disabled": null,
"schedule": null,
"parameters": {
"batchSize": null,
"maxFailedItems": -1,
"maxFailedItemsPerBatch": null,
"base64EncodeKeys": null,
"configuration": {
"indexedFileNameExtensions": ".pdf,.docx,.doc",
"dataToExtract": "contentAndMetadata",
"failOnUnprocessableDocument": false,
"failOnUnsupportedContentType": false,
"indexStorageMetadataOnlyForOversizedDocuments": true,
"allowSkillsetToReadFileData": true
}
},
"fieldMappings": [],
"outputFieldMappings": [
{
"sourceFieldName": "/document/content/procuradores",
"targetFieldName": "procuradores"
}
],
"cache": null,
"encryptionKey": null
}
This is my index:
{
"name": "customer-documents",
"fields": [
{
"name": "key",
"type": "Edm.String",
"facetable": true,
"filterable": true,
"key": true,
"retrievable": true,
"searchable": false,
"sortable": true,
"analyzer": null,
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "content",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"key": false,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "es.lucene",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "procuradores",
"type": "Edm.String",
"facetable": false,
"filterable": true,
"key": false,
"retrievable": true,
"searchable": false,
"sortable": false,
"analyzer": null,
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
}
],
"suggesters": [],
"scoringProfiles": [],
"defaultScoringProfile": null,
"corsOptions": null,
"analyzers": [],
"charFilters": [],
"tokenFilters": [],
"tokenizers": [],
"similarity": {
"#odata.type": "#Microsoft.Azure.Search.BM25Similarity",
"k1": null,
"b": null
},
"encryptionKey": null,
"#odata.etag": "\"0x8D98BC85E9F6996\""
}
My skill set definition:
{
"name": "skillset-procuradores",
"description": "",
"skills": [
{
"#odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
"name": "procuradores",
"description": "",
"context": "/document",
"uri": "my url ommited for secure reasons",
"httpMethod": "POST",
"timeout": "PT3M50S",
"batchSize": 1,
"degreeOfParallelism": null,
"inputs": [
{
"name": "text",
"source": "/document/content"
}
],
"outputs": [
{
"name": "procuradores",
"targetName": "procuradores"
}
],
"httpHeaders": {}
}
],
"cognitiveServices": null,
"knowledgeStore": null,
"encryptionKey": null
}
And finally my function output:
{
"values": [
{
"recordId": "1",
"data": {
"procuradores": "people's names"
}
}
]
}
What am I missing?
Rafael, can you give debug sessions a try? I suspect there is something happening in your custom skill that means the data is not coming back. By using this, you can test the actual input and output.
https://learn.microsoft.com/en-us/azure/search/cognitive-search-debug-session
This is just a hunch, but in the indexer definition, try changing your output field mapping sourceFieldName from "/document/content/procuradores" to "/document/procuradores". The context that you are giving in the skill is just "/document" so it should append the output onto that.

How to fetch multiple values from a nested JSON like output

I am looking forward a way to list the value from a nested variable (which has dict and list values) ie register which is response_find and I have that in mostly json format and most of the values inside the json are nested within [] list like construct.
It works somehow if I get individual values from it like below:
var=response_find['json']['results'][0]['content_facet_attributes']
or
var=response_find['json']['results'][0]['certname']
But did not work when I did below:
var=response_find['json']['results'][0]['content_view_id']
Below are few values which I'm looking forward to fetch from this nested output:
"architecture_name": "x86_64",
"name": "satcap.rest.example.com",
"url": "https://satcap.rest.example.com:9090"
"content_source_name": "satcap.rest.example.com",
"name": "ccv-azure-infra-rhel7"
"name": "Prod"
"id": 33485,
"ip": "192.168.88.88",
"name": "invwharn108.test.exampl.com",
"registered_through": "satcap.rest.example.com"
Nested Json output:
{
"response_find": {
"apipie_checksum": "7533ab625c45a3819647f4fb4c9394c2832c0180",
"cookies": {
"_session_id": "25872833d9e2723073797fbd8cfa2d63"
},
"cookies_string": "_session_id=25872833d9e2723073797fbd8cfa2d63",
"foreman_version": "1.24.1.21",
"json": {
"page": 1,
"per_page": 20,
"results": [
{
"architecture_id": 1,
"architecture_name": "x86_64",
"build": false,
"capabilities": [
"build"
],
"certname": "invwharn108.test.exampl.com",
"comment": null,
"content_facet_attributes": {
"applicable_module_stream_count": 0,
"applicable_package_count": 0,
"content_source": {
"id": 17,
"name": "satcap.rest.example.com",
"url": "https://satcap.rest.example.com:9090"
},
"content_source_id": 17,
"content_source_name": "satcap.rest.example.com",
"content_view": {
"id": 67,
"name": "ccv-azure-infra-rhel7"
},
"content_view_id": 67,
"content_view_name": "ccv-azure-infra-rhel7",
"errata_counts": {
"bugfix": 0,
"enhancement": 0,
"security": 0,
"total": 0
},
"id": 32255,
"kickstart_repository": {
"id": 5772,
"name": "Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.8"
},
"kickstart_repository_id": 5772,
"kickstart_repository_name": "5772",
"lifecycle_environment": {
"id": 5,
"name": "Prod"
},
"lifecycle_environment_id": 5,
"lifecycle_environment_name": "Prod",
"upgradable_module_stream_count": 0,
"upgradable_package_count": 0,
"uuid": "dab2d66b-1a73-490a-aa9d-3f036658980a"
},
"created_at": "2020-12-23 13:19:35 UTC",
"disk": null,
"domain_id": 25,
"domain_name": "test.example-aws.example.com",
"enabled": true,
"environment_id": null,
"environment_name": null,
"errata_status": 1,
"errata_status_label": "Could not calculate errata status, ensure host is registered and the katello-host-tools package is installed",
"global_status": 1,
"global_status_label": "Warning",
"hostgroup_id": 982,
"hostgroup_name": "infra",
"hostgroup_title": "NXDI-hg-aws/west-europe/infra",
"id": 33485,
"image_file": "",
"image_id": null,
"image_name": null,
"installed_at": null,
"ip": "192.168.88.88",
"ip6": null,
"last_compile": "2020-12-23 13:19:38 UTC",
"last_report": null,
"location_id": 37,
"location_name": "west-europe",
"mac": "02:78:43:60:ee:fb",
"managed": false,
"medium_id": null,
"medium_name": null,
"model_id": 25,
"model_name": "HVM domU",
"name": "invwharn108.test.exampl.com",
"openscap_proxy": null,
"openscap_proxy_id": null,
"openscap_proxy_name": null,
"operatingsystem_id": 21,
"operatingsystem_name": "RedHat 7.8",
"organization_id": 3,
"pxe_loader": "PXELinux BIOS",
"subnet_id": 65,
"subnet_name": "aws-west-europe-infra",
"subscription_facet_attributes": {
"autoheal": true,
"hypervisor": false,
"id": 33593,
"last_checkin": "2020-12-23 13:19:42 UTC",
"purpose_addons": [],
"purpose_role": "",
"purpose_usage": "",
"registered_at": "2020-12-23 13:19:35 UTC",
"registered_through": "satcap.rest.example.com",
},
"subscription_global_status": 1,
"subscription_status": 1,
"subscription_status_label": "Partially entitled",
}
],
"search": "name=invwharn108.test.exampl.com",
"sort": {
"by": null,
"order": null
},
"subtotal": 1,
"total": 13121
},
"msg": "OK (unknown bytes)",
"x_request_id": "e02dd9b3-b2f8-4c39-8bf5-1ce1897d9548",
}
}
My Play:
---
- hosts: localhost
tasks:
- include_vars: vaults/aws_secrets.yml
no_log: true
- include_vars: requirements.yml
no_log: true
- name: Find the ID of Cloud VM in Satellite
uri:
url: "https://{{ satserver }}/api/v2/hosts?search=name={{ aws_instance_name }}"
method: GET
user: "{{ aws_satuser }}"
password: "{{ aws_satpw }}"
force_basic_auth: yes
validate_certs: no
register: response_find
delegate_to: localhost
changed_when: false
- debug:
var=response_find['json']['results'][0]['content_facet_attributes']
#var=response_find.json.results.0.organization_name
#var=response_find['json']['results'][0]['certname']
Result:
"content_facet_attributes": {
"applicable_module_stream_count": 0,
"applicable_package_count": 0,
"content_source": {
"id": 17,
"name": "satcap.rest.example.com",
"url": "https://satcap.rest.example.com:9090"
},
"content_source_id": 17,
"content_source_name": "satcap.rest.example.com",
"content_view": {
"id": 67,
"name": "ccv-azure-infra-rhel7"
},
"content_view_id": 67,
"content_view_name": "ccv-azure-infra-rhel7",
"errata_counts": {
"bugfix": 0,
"enhancement": 0,
"security": 0,
"total": 0
},
"id": 32255,
"kickstart_repository": {
"id": 5772,
"name": "Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.8"
},
"kickstart_repository_id": 5772,
"kickstart_repository_name": "5772",
"lifecycle_environment": {
"id": 5,
"name": "Prod"
},
"lifecycle_environment_id": 5,
"lifecycle_environment_name": "Prod",
"upgradable_module_stream_count": 0,
"upgradable_package_count": 0,
"uuid": "dab2d66b-1a73-490a-aa9d-3f036658980a"
},
If you want to do a dictionary out of those data you listed, you could use the filter json_query, which is using JMESPath to parse and process JSON.
In order to extract a dictionary looking like:
{
"architecture_name": "x86_64",
"content_source_name": "satcap.rest.example.com",
"content_source_url": "https://satcap.rest.example.com:9090",
"content_view_name": "ccv-azure-infra-rhel7",
"egistered_through": "satcap.rest.example.com",
"id": 33485,
"ip": "192.168.88.88",
"lifecycle_environment_name": "Prod",
"name": "invwharn108.test.exampl.com"
}
You could use JMESPath to filter multiselect hashes.
Here is a JMESPath query that would give this result:
json.results[*].{
"architecture_name": architecture_name,
"content_source_name": content_facet_attributes.content_source.name,
"content_source_url": content_facet_attributes.content_source.url,
"content_view_name": content_facet_attributes.content_view.name,
"lifecycle_environment_name": content_facet_attributes.lifecycle_environment.name,
"id": id,
"ip": ip,
"name": name,
"egistered_through": subscription_facet_attributes.registered_through
}
Here is an example playbook using this:
- hosts: localhost
gather_facts: no
tasks:
- debug:
msg: >-
{{
(
response_find | json_query('
json.results[*].{
"architecture_name": architecture_name,
"content_source_name": content_facet_attributes.content_source.name,
"content_source_url": content_facet_attributes.content_source.url,
"content_view_name": content_facet_attributes.content_view.name,
"lifecycle_environment_name": content_facet_attributes.lifecycle_environment.name,
"id": id,
"ip": ip,
"name": name,
"egistered_through": subscription_facet_attributes.registered_through
}
')
).0
}}
vars:
{
"response_find": {
"apipie_checksum": "7533ab625c45a3819647f4fb4c9394c2832c0180",
"cookies": {
"_session_id": "25872833d9e2723073797fbd8cfa2d63"
},
"cookies_string": "_session_id=25872833d9e2723073797fbd8cfa2d63",
"foreman_version": "1.24.1.21",
"json": {
"page": 1,
"per_page": 20,
"results": [{
"architecture_id": 1,
"architecture_name": "x86_64",
"build": false,
"capabilities": [
"build"
],
"certname": "invwharn108.test.exampl.com",
"comment": null,
"content_facet_attributes": {
"applicable_module_stream_count": 0,
"applicable_package_count": 0,
"content_source": {
"id": 17,
"name": "satcap.rest.example.com",
"url": "https://satcap.rest.example.com:9090"
},
"content_source_id": 17,
"content_source_name": "satcap.rest.example.com",
"content_view": {
"id": 67,
"name": "ccv-azure-infra-rhel7"
},
"content_view_id": 67,
"content_view_name": "ccv-azure-infra-rhel7",
"errata_counts": {
"bugfix": 0,
"enhancement": 0,
"security": 0,
"total": 0
},
"id": 32255,
"kickstart_repository": {
"id": 5772,
"name": "Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.8"
},
"kickstart_repository_id": 5772,
"kickstart_repository_name": "5772",
"lifecycle_environment": {
"id": 5,
"name": "Prod"
},
"lifecycle_environment_id": 5,
"lifecycle_environment_name": "Prod",
"upgradable_module_stream_count": 0,
"upgradable_package_count": 0,
"uuid": "dab2d66b-1a73-490a-aa9d-3f036658980a"
},
"created_at": "2020-12-23 13:19:35 UTC",
"disk": null,
"domain_id": 25,
"domain_name": "test.example-aws.example.com",
"enabled": true,
"environment_id": null,
"environment_name": null,
"errata_status": 1,
"errata_status_label": "Could not calculate errata status, ensure host is registered and the katello-host-tools package is installed",
"global_status": 1,
"global_status_label": "Warning",
"hostgroup_id": 982,
"hostgroup_name": "infra",
"hostgroup_title": "NXDI-hg-aws/west-europe/infra",
"id": 33485,
"image_file": "",
"image_id": null,
"image_name": null,
"installed_at": null,
"ip": "192.168.88.88",
"ip6": null,
"last_compile": "2020-12-23 13:19:38 UTC",
"last_report": null,
"location_id": 37,
"location_name": "west-europe",
"mac": "02:78:43:60:ee:fb",
"managed": false,
"medium_id": null,
"medium_name": null,
"model_id": 25,
"model_name": "HVM domU",
"name": "invwharn108.test.exampl.com",
"openscap_proxy": null,
"openscap_proxy_id": null,
"openscap_proxy_name": null,
"operatingsystem_id": 21,
"operatingsystem_name": "RedHat 7.8",
"organization_id": 3,
"pxe_loader": "PXELinux BIOS",
"subnet_id": 65,
"subnet_name": "aws-west-europe-infra",
"subscription_facet_attributes": {
"autoheal": true,
"hypervisor": false,
"id": 33593,
"last_checkin": "2020-12-23 13:19:42 UTC",
"purpose_addons": [],
"purpose_role": "",
"purpose_usage": "",
"registered_at": "2020-12-23 13:19:35 UTC",
"registered_through": "satcap.rest.example.com"
},
"subscription_global_status": 1,
"subscription_status": 1,
"subscription_status_label": "Partially entitled"
}],
"search": "name=invwharn108.test.exampl.com",
"sort": {
"by": null,
"order": null
},
"subtotal": 1,
"total": 13121
},
"msg": "OK (unknown bytes)",
"x_request_id": "e02dd9b3-b2f8-4c39-8bf5-1ce1897d9548"
}
}
Which gives the recap:
PLAY [localhost] *************************************************************************************************
TASK [debug] *****************************************************************************************************
ok: [localhost] => {
"msg": {
"architecture_name": "x86_64",
"content_source_name": "satcap.rest.example.com",
"content_source_url": "https://satcap.rest.example.com:9090",
"content_view_name": "ccv-azure-infra-rhel7",
"egistered_through": "satcap.rest.example.com",
"id": 33485,
"ip": "192.168.88.88",
"lifecycle_environment_name": "Prod",
"name": "invwharn108.test.exampl.com"
}
}
PLAY RECAP *******************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Network IP addresses with jq bash command from docker inspect

I want to process docker inspect <container1> <container2> out to retrieve via jq command exposed ports and IPAddresses assigned to defined networks. So far I've got jq '{(.[].Name): getpath(path(.[].NetworkSettings.Networks)) | .[].IPAddress}' which is clearly far from enough.
p.s. I know its easy to write a script that would give such output but I'm curious how to do that using jq
Expected output
{
# .[].Name
"/prometheus_prometheus_1": [
[
# .[].Config.ExposedPorts
"9090/tcp"
],
{
# key = .[].NetworkSettings.Networks.<index>
# value = .[].NetworkSettings.Networks[].IPAddress
"prometheus_internal": "172.21.0.4",
"system-information": "172.28.0.2"
}
]
}
Input:
[
{
"Id": "c2f86bce68441f50f973ae89a835d052e74c083e35b5438f3cec2497bcac79fa",
"Created": "2018-06-12T05:33:19.811448302Z",
"Path": "/bin/prometheus",
"Args": [
"--config.file=/etc/prometheus/prometheus.yml",
"--storage.tsdb.path=/prometheus",
"--web.console.libraries=/usr/share/prometheus/console_libraries",
"--web.console.templates=/usr/share/prometheus/consoles"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 13217,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-06-12T05:33:20.264845701Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:44a4c1c270dcb5e8caf51e3205fa23343cc903f3823eab53ae204f304d16f62a",
"ResolvConfPath": "/var/lib/docker/containers/c2f86bce68441f50f973ae89a835d052e74c083e35b5438f3cec2497bcac79fa/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/c2f86bce68441f50f973ae89a835d052e74c083e35b5438f3cec2497bcac79fa/hostname",
"HostsPath": "/var/lib/docker/containers/c2f86bce68441f50f973ae89a835d052e74c083e35b5438f3cec2497bcac79fa/hosts",
"LogPath": "/var/lib/docker/containers/c2f86bce68441f50f973ae89a835d052e74c083e35b5438f3cec2497bcac79fa/c2f86bce68441f50f973ae89a835d052e74c083e35b5438f3cec2497bcac79fa-json.log",
"Name": "/prometheus_prometheus_1",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"prometheus_prometheus-data:/prometheus:rw",
"/home/sebastian/projects/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:rw"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "prometheus_internal",
"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
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/73c16b0735eb15494741e5b821a9df3be8cebb716219ac206d9ee0042e4166ac-init/diff:/var/lib/docker/overlay2/03c66042305488fea2fe693246e90374743fbb7836ab31e4ee5cdbfbb1c97785/diff:/var/lib/docker/overlay2/80821a00b79334493729e671dfb66cc878aec19fe2d0dfbaf4cde187522b06e8/diff:/var/lib/docker/overlay2/f5071cce5513fb3c465ad883297157271ef48c6f59cd88768068224d850c6903/diff:/var/lib/docker/overlay2/c9a0cc617abb45fbd4572abb41c7281c96bc9d59c109270c7f1ec7a99f5b055b/diff:/var/lib/docker/overlay2/5b425f8a440139a8fdcdd7f7fee8189565e9e00304e96f4cfee86ff6b861e068/diff:/var/lib/docker/overlay2/e85740d997591d2f60bfa61ea0c82a58636bccaaba970e55f12cf0ff24565c70/diff:/var/lib/docker/overlay2/e9c362d971c460b02111122b241888392d77c5b8545ed520c3d74660b16db9b2/diff:/var/lib/docker/overlay2/5001184fc8ddd25204626f419c1530b970cb37f936a196fb1173f2774310085e/diff:/var/lib/docker/overlay2/ed2e676f09a4583f2194e752083a7c95be80131f055891dc39f9fed5560f5a73/diff",
"MergedDir": "/var/lib/docker/overlay2/73c16b0735eb15494741e5b821a9df3be8cebb716219ac206d9ee0042e4166ac/merged",
"UpperDir": "/var/lib/docker/overlay2/73c16b0735eb15494741e5b821a9df3be8cebb716219ac206d9ee0042e4166ac/diff",
"WorkDir": "/var/lib/docker/overlay2/73c16b0735eb15494741e5b821a9df3be8cebb716219ac206d9ee0042e4166ac/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "volume",
"Name": "prometheus_prometheus-data",
"Source": "/var/lib/docker/volumes/prometheus_prometheus-data/_data",
"Destination": "/prometheus",
"Driver": "local",
"Mode": "rw",
"RW": true,
"Propagation": ""
},
{
"Type": "bind",
"Source": "/home/sebastian/projects/prometheus/prometheus.yml",
"Destination": "/etc/prometheus/prometheus.yml",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "c2f86bce6844",
"Domainname": "",
"User": "nobody",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"9090/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"--config.file=/etc/prometheus/prometheus.yml",
"--storage.tsdb.path=/prometheus",
"--web.console.libraries=/usr/share/prometheus/console_libraries",
"--web.console.templates=/usr/share/prometheus/consoles"
],
"Image": "prom/prometheus:v2.3.0",
"Volumes": {
"/etc/prometheus/prometheus.yml": {},
"/prometheus": {}
},
"WorkingDir": "/prometheus",
"Entrypoint": [
"/bin/prometheus"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "b8ff39fd239739ae66051752c1b49b0119862b8f21678fb42400c907d25b1c57",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "prometheus",
"com.docker.compose.service": "prometheus",
"com.docker.compose.version": "1.16.1",
"maintainer": "The Prometheus Authors <prometheus-developers#googlegroups.com>"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "7be77954d0e6990f565a8526b157236140238cabf0954629598ce3bb9aaae885",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"9090/tcp": null
},
"SandboxKey": "/var/run/docker/netns/7be77954d0e6",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"prometheus_internal": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"prometheus",
"c2f86bce6844"
],
"NetworkID": "145c59986c16003f9a3a30e6b671c34b56225d90243fba88fc295c49b4dcfff6",
"EndpointID": "8e3ac8bd4719ea85358c20a8141c37377dd327265916d41ee5d1db6b7496898c",
"Gateway": "172.21.0.1",
"IPAddress": "172.21.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:15:00:04",
"DriverOpts": null
},
"system-information": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"prometheus",
"c2f86bce6844"
],
"NetworkID": "f6e67721cb73da7e8d4eacdb709de240014af9af35e66216e6186300c72de330",
"EndpointID": "2c31369f8175f2b38a5bc966a8306c8f0f11ac4c264e6ce735d00c87b8a6f44f",
"Gateway": "172.28.0.1",
"IPAddress": "172.28.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:1c:00:02",
"DriverOpts": null
}
}
}
}
]
jq solution:
jq '.[] | {(.Name) : [(.Config.ExposedPorts | keys),
(.NetworkSettings.Networks | to_entries
| map({(.key): .value.IPAddress}) | add)
]
}' input
The output:
{
"/prometheus_prometheus_1": [
[
"9090/tcp"
],
{
"prometheus_internal": "172.21.0.4",
"system-information": "172.28.0.2"
}
]
}

wordpress docker exits immediately

I’m trying to get wordpress up and running with docker on OSX 10.12.1...
First I start up mysql:
docker run --name dockermysql -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=secret -d mysql:5
That seems to work fine:
$ docker ps -a
f7d1562def4a mysql:5 "docker-entrypoint.sh" 33 minutes ago Up 33 minutes 3306/tcp dockermysql
but then I try wordpress…
docker run --name dockerpress --link dockermysql:mysql -d wordpress --net="host" -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=secret
and it seems like it exits immediately
$ docker ps -a
84cc4d2abb57 wordpress "docker-entrypoint.sh" 7 minutes ago Exited (2) 7 minutes ago dockerpress
f7d1562def4a mysql:5 "docker-entrypoint.sh" 33 minutes ago Up 33 minutes 3306/tcp dockermysql
Here are the results of docker inspect dockerpress:
[
{
"Id": "84cc4d2abb57d00fbd67d10c02cc6333a401a7d8bfe4bc15f588da11a834333f",
"Created": "2016-11-28T14:41:04.757044577Z",
"Path": "docker-entrypoint.sh",
"Args": [
"--net=host",
"-e",
"WORDPRESS_DB_USER=wordpress",
"-e",
"WORDPRESS_DB_PASSWORD=secret"
],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 2,
"Error": "",
"StartedAt": "2016-11-28T14:41:05.523186975Z",
"FinishedAt": "2016-11-28T14:41:05.619181506Z"
},
"Image": "sha256:ee397259d4e59c65e2c1c5979a3634eb3ab106bba389acea8b21862053359134",
"ResolvConfPath": "/var/lib/docker/containers/84cc4d2abb57d00fbd67d10c02cc6333a401a7d8bfe4bc15f588da11a834333f/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/84cc4d2abb57d00fbd67d10c02cc6333a401a7d8bfe4bc15f588da11a834333f/hostname",
"HostsPath": "/var/lib/docker/containers/84cc4d2abb57d00fbd67d10c02cc6333a401a7d8bfe4bc15f588da11a834333f/hosts",
"LogPath": "/var/lib/docker/containers/84cc4d2abb57d00fbd67d10c02cc6333a401a7d8bfe4bc15f588da11a834333f/84cc4d2abb57d00fbd67d10c02cc6333a401a7d8bfe4bc15f588da11a834333f-json.log",
"Name": "/dockerpress",
"RestartCount": 0,
"Driver": "aufs",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": [
"/dockermysql:/dockerpress/mysql"
],
"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,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Name": "aufs",
"Data": null
},
"Mounts": [
{
"Name": "928da9b62b2adb3dd93905dfd702b766d80f0e7bb6f17b7e7f57f7c6433bdc5d",
"Source": "/var/lib/docker/volumes/928da9b62b2adb3dd93905dfd702b766d80f0e7bb6f17b7e7f57f7c6433bdc5d/_data",
"Destination": "/var/www/html",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "84cc4d2abb57",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"no_proxy=*.local, 169.254/16",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"PHPIZE_DEPS=autoconf \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",
"GPG_KEYS=0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3",
"PHP_VERSION=5.6.28",
"PHP_URL=https://secure.php.net/get/php-5.6.28.tar.xz/from/this/mirror",
"PHP_ASC_URL=https://secure.php.net/get/php-5.6.28.tar.xz.asc/from/this/mirror",
"PHP_SHA256=07187ba2870f89cef334cd2ad6cb801aeec5eaf283da0293a9a6be75d6786d11",
"PHP_MD5=1e01c66b2e67ab3b56a6180ee560fe4c",
"WORDPRESS_VERSION=4.6.1",
"WORDPRESS_SHA1=027e065d30a64720624a7404a1820e6c6fff1202"
],
"Cmd": [
"--net=host",
"-e",
"WORDPRESS_DB_USER=wordpress",
"-e",
"WORDPRESS_DB_PASSWORD=secret"
],
"Image": "wordpress",
"Volumes": {
"/var/www/html": {}
},
"WorkingDir": "/var/www/html",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "d946a78e9a50fc8fb10873a0c043c9f49a377db44b19edb5e83362b37c025948",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": null,
"SandboxKey": "/var/run/docker/netns/d946a78e9a50",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "37e08b5c5d5f8a159552b8ab22a0fb37bfbcfd720fd83ce20a983ab85e60157f",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": ""
}
}
}
}
]
For anyone still learning, like me, I found the better solution here was to use docker-compose as described in the docs here: https://docs.docker.com/compose/wordpress/
One nice thing about this, aside from the fact that it's way easier to deal with, is you can see all of your env variables to avoid mismatched variables between your db and wp server - which is what was causing my initial problem
It worked for me to pull image version 5.7 for mysql and wordpress the latest image version.
Manual who i created it:
---1. docker pull wordpress
---2. docker pull mysql:5.7
---3. docker run --name nwplm-database -e MYSQL_ROOT_PASSWORD=Pa$$w0rd -d mysql:5.7
---4. docker run --name nwplm-wordpress --link nwplm-database -p 8080:80 -e WORDPRESS_DB_HOST=nwplm-database:3306 -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=Pa$$w0rd -e WORDPRESS_DB_NAME=nwplm-wordpress -e WORDPRESS_TABLE_PREFIX=wp_ -d wordpress
---5. open localhost:8080 in your browser

Ansible: EC2 provisioning and Iterations

I am trying to start a bunch of EC2 instances, then install something on them based on the IP given by AWS. With only one EC2, I can add the host and proceed without any issue,but when I chain them using with_dict, I can't achieve it anymore...
The following runs as I want, but I can't understand how to deal with the registered variable ec2_infos I got from the provisioning...
- name: Create Test EC2 instances
ec2:
group: default
image: ami-40d28157
instance_type: '{{item.value.type}}'
instance_tags:
Name: "{{ tag+'-'+item.value.name }}"
key_name: privatekey
region: us-west-1
vpc_subnet_id: subnet-REDACTD
wait: yes
with_dict: '{{ec2_stack}}'
register: ec2_infos
With a dictionary like
ec2_stack:
serv1:
type: t2.micro
name: server1
serv2:
type: t2.small
name: server2
ec2_infos is structures like:
"ec2_infos": {
"changed": true,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"instance_ids": [
"i-0fewq09812ddq6"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/sda1": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-0987654"
}
},
"dns_name": "",
"ebs_optimized": false,
"groups": {
"sg-qdwdww": "default"
},
"hypervisor": "xen",
"id": "i-083665656521dwq6",
"image_id": "ami-40d28157",
"launch_time": "2016-11-24T20:38:53.000Z",
"placement": "us-west-1d",
"private_ip": "x.x.x.x",
"public_dns_name": "",
"public_ip": null,
"ramdisk": null,
"region": "us-east-1",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"tags": {
"Name": "server1",
"Team": "blah"
},
"tenancy": "default","tenancy": "default",
"virtualization_type": "hvm"
}
],
"invocation": {
"module_args": {
"assign_public_ip": false,
"exact_count": null,
"group": [
"default"
],
"group_id": null,
"id": null,
"image": "ami-40d28157",
"instance_ids": null,
"instance_initiated_shutdown_behavior": null,
"instance_profile_name": null,
"instance_tags": {
"Name": "server1",
"Team": "blah"
},
"instance_type": "t2.micro",
"kernel": null,
"volumes": null,
"vpc_subnet_id": "subnet-abcdfed",
"wait": true,
"wait_timeout": "300",
"zone": null
},
"module_name": "ec2"
},
"item": {
"key": "serv1",
"value": {
"name": "server1",
"type": "t2.micro"
}
},
"tagged_instances": []
},
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"instance_ids": [
"i-0971278624334fd"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/sda1": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-9999999"
}
},
"dns_name": "",
"ebs_optimized": false,
"groups": {
"sg-redactd": "default"
},
"launch_time": "2016-11-24T20:39:21.000Z",
"private_ip": "y.y.y.y",
"public_dns_name": "",
"public_ip": null,
"ramdisk": null,
"state": "running",
"state_code": 16,
"tags": {
"Name": "serv2",
"Team": "blah"
},
"tenancy": "default",
"virtualization_type": "hvm"
}
],
"invocation": {
"module_args": {
"assign_public_ip": false,
"wait_timeout": "300",
"zone": null
},
"module_name": "ec2"
},
"item": {
"key": "server2",
"value": {
"name": "serv2",
"type": "t2.small"
}
},
"tagged_instances": []
}
]
}
I tried with_items and with_subelements in different ways, but I can't manage to get every IPs of the new EC2. I don't even need to sort them just extract them from the instances part and feed them to add_host so I can proceed.
Anybody knows a clean way to do so, or would be kind enough to explain to me how to deal with a registered variable after a loop properly ?
Answer from the comments:
ec2_infos.results | map(attribute='instances') | sum(start=[]) | map(attribute='private_ip') | list