[{"data":1,"prerenderedAt":757},["ShallowReactive",2],{"Categories":3,"NavIndexCategoriesCountFooter":203,"content-\u002F2022\u002F02\u002F22\u002Fr2dbc-postgresql-invalid-ipv6-address-when-dockerized\u002F":204},[4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,68,70,71,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202],{"category":5},"System Administration",{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},"Software Development",{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":27},{"category":27},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":5},{"category":27},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":27},{"category":27},{"category":67},"Drones & RC",{"category":69},"DIY Projects",{"category":67},{"category":72},"Photography",{"category":69},{"category":69},{"category":69},{"category":67},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":69},{"category":67},{"category":69},{"category":69},{"category":67},{"category":67},{"category":72},{"category":72},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":5},{"category":5},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":5},{"category":67},{"category":67},{"category":72},{"category":72},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":67},{"category":72},{"category":67},{"category":138},"3D Printing - Laser Cutting - CNC",{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":138},{"category":5},{"category":138},{"category":27},{"category":27},{"category":138},{"category":138},{"category":72},{"category":158},"Photography,3D Printing - Laser Cutting - CNC",{"category":27},{"category":27},{"category":69},{"category":27},{"category":27},{"category":27},{"category":27},{"category":5},{"category":67},{"category":5},{"category":5},{"category":27},{"category":27},{"category":27},{"category":27},{"category":27},{"category":69},{"category":27},{"category":27},{"category":27},{"category":27},{"category":181},"Home Assistant",{"category":181},{"category":72},{"category":27},{"category":27},{"category":72},{"category":138},{"category":5},{"category":72},{"category":72},{"category":138},{"category":27},{"category":181},{"category":181},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},{"category":72},191,{"id":205,"title":206,"body":207,"category":27,"date":739,"description":213,"embedImage":740,"extension":741,"image":740,"intro":742,"meta":743,"navigation":744,"path":745,"seo":746,"series":740,"sitemap":747,"stem":748,"tags":749,"__hash__":756},"content\u002F2022\u002F02\u002F22\u002Fr2dbc-postgresql-invalid-ipv6-address-when-dockerized.md","r2dbc-postgresql - invalid ipv6 address when dockerized",{"type":208,"value":209,"toc":733},"minimark",[210,214,217,220,233,236,239,250,253,265,268,291,296,299,302,328,331,381,384,443,447,450,453,475,478,498,501,507,510,516,519,523,526,541,544,548,551,554,588,591,617,620,643,646,664,667,720,723,726,729],[211,212,213],"p",{},"I was testing out R2DBC inside spring boot with kotlin's coroutines - and it was working fine while I was developing it.",[211,215,216],{},"The develop setup was simple - a docker container for the actual postgres database - exposing the standard port 5432 on localhost - and then just run the kotlin boot app.",[211,218,219],{},"However - once I wanted to add this to staging - the setup changes - the following were set up in docker:",[221,222,223,227,230],"ul",{},[224,225,226],"li",{},"docker network for the app (bridge driver)",[224,228,229],{},"postgres container",[224,231,232],{},"app container",[211,234,235],{},"And suddenly - although flyway could talk to the database via jdbc - the r2dbc connection was failing.",[211,237,238],{},"The connection string looked like this:",[240,241,247],"pre",{"className":242,"code":244,"language":245,"meta":246},[243],"language-text","r2dbc:pool:postgresql:\u002F\u002F${DB_HOST}:${DB_PORT}\u002Fdb_name\n","text","",[248,249,244],"code",{"__ignoreMap":246},[211,251,252],{},"So - I had to create a test harness to see what was going on.",[211,254,255],{},[256,257,264],"a",{"href":258,"rel":259,"target":263},"https:\u002F\u002Fgithub.com\u002Fchrissearle\u002Fr2dbc-pg-test",[260,261,262],"nofollow","noopener","noreferer","_blank","Repository on GitHub",[211,266,267],{},"First up - you need to build the application:",[240,269,273],{"className":270,"code":271,"language":272,"meta":246,"style":246},"language-shell shiki shiki-themes github-dark","mvn clean package\n","shell",[248,274,275],{"__ignoreMap":246},[276,277,280,284,288],"span",{"class":278,"line":279},"line",1,[276,281,283],{"class":282},"svObZ","mvn",[276,285,287],{"class":286},"sU2Wk"," clean",[276,289,290],{"class":286}," package\n",[292,293,295],"h2",{"id":294},"development","Development",[211,297,298],{},"Now - let's try running it as if we were in development:",[211,300,301],{},"We'll start up a local db container for testing (with some options to make sure it's a clean instance)",[240,303,305],{"className":270,"code":304,"language":272,"meta":246,"style":246},"docker-compose -f docker-compose-test-1.yml up --force-recreate -V\n",[248,306,307],{"__ignoreMap":246},[276,308,309,312,316,319,322,325],{"class":278,"line":279},[276,310,311],{"class":282},"docker-compose",[276,313,315],{"class":314},"sDLfK"," -f",[276,317,318],{"class":286}," docker-compose-test-1.yml",[276,320,321],{"class":286}," up",[276,323,324],{"class":314}," --force-recreate",[276,326,327],{"class":314}," -V\n",[211,329,330],{},"And then run the appliation",[240,332,334],{"className":270,"code":333,"language":272,"meta":246,"style":246},"DB_HOST=localhost DB_PORT=5432 DB_USER=test DB_PASSWORD=test java -jar target\u002Ftest-pg-r2dbc.jar\n",[248,335,336],{"__ignoreMap":246},[276,337,338,342,346,349,352,354,357,360,362,365,368,370,372,375,378],{"class":278,"line":279},[276,339,341],{"class":340},"s95oV","DB_HOST",[276,343,345],{"class":344},"snl16","=",[276,347,348],{"class":286},"localhost",[276,350,351],{"class":340}," DB_PORT",[276,353,345],{"class":344},[276,355,356],{"class":286},"5432",[276,358,359],{"class":340}," DB_USER",[276,361,345],{"class":344},[276,363,364],{"class":286},"test",[276,366,367],{"class":340}," DB_PASSWORD",[276,369,345],{"class":344},[276,371,364],{"class":286},[276,373,374],{"class":282}," java",[276,376,377],{"class":314}," -jar",[276,379,380],{"class":286}," target\u002Ftest-pg-r2dbc.jar\n",[211,382,383],{},"The application runs and you should get something like this at the end of the logs:",[240,385,389],{"className":386,"code":387,"language":388,"meta":246,"style":246},"language-log shiki shiki-themes github-dark","YYYY-MM-DD HH:MM:SS.SSS  INFO THREADID --- [           main] n.c.testpgr2dbc.TestPgR2dbcApplication   : Sample(id=1, name=Name)\nYYYY-MM-DD HH:MM:SS.SSS  INFO THREADID --- [tor-tcp-epoll-1] n.c.testpgr2dbc.TestPgR2dbcApplication   : Sample(id=1, name=Name)\n","log",[248,390,391,418],{"__ignoreMap":246},[276,392,393,396,399,403,406,409,412,415],{"class":278,"line":279},[276,394,395],{"class":340},"YYYY-MM-DD HH:MM:",[276,397,398],{"class":314},"SS.SSS",[276,400,402],{"class":401},"s4JwU","  INFO",[276,404,405],{"class":340}," THREADID --- [           main] ",[276,407,408],{"class":314},"n.c.testpgr2dbc.TestPgR2dbcApplication",[276,410,411],{"class":340},"   : Sample(id=",[276,413,414],{"class":314},"1",[276,416,417],{"class":340},", name=Name)\n",[276,419,421,423,425,427,430,432,435,437,439,441],{"class":278,"line":420},2,[276,422,395],{"class":340},[276,424,398],{"class":314},[276,426,402],{"class":401},[276,428,429],{"class":340}," THREADID --- [tor-tcp-epoll-",[276,431,414],{"class":314},[276,433,434],{"class":340},"] ",[276,436,408],{"class":314},[276,438,411],{"class":340},[276,440,414],{"class":314},[276,442,417],{"class":340},[292,444,446],{"id":445},"stagingproduction","Staging\u002FProduction",[211,448,449],{},"So let's mimic a staging setup.",[211,451,452],{},"First - we need to package the app into docker:",[240,454,456],{"className":270,"code":455,"language":272,"meta":246,"style":246},"docker build -t test-pg-r2dbc:latest .\n",[248,457,458],{"__ignoreMap":246},[276,459,460,463,466,469,472],{"class":278,"line":279},[276,461,462],{"class":282},"docker",[276,464,465],{"class":286}," build",[276,467,468],{"class":314}," -t",[276,470,471],{"class":286}," test-pg-r2dbc:latest",[276,473,474],{"class":286}," .\n",[211,476,477],{},"Now we can run up the more complex docker setup:",[240,479,481],{"className":270,"code":480,"language":272,"meta":246,"style":246},"docker-compose -f docker-compose-test-2.yml up --force-recreate -V\n",[248,482,483],{"__ignoreMap":246},[276,484,485,487,489,492,494,496],{"class":278,"line":279},[276,486,311],{"class":282},[276,488,315],{"class":314},[276,490,491],{"class":286}," docker-compose-test-2.yml",[276,493,321],{"class":286},[276,495,324],{"class":314},[276,497,327],{"class":314},[211,499,500],{},"This time the logs show postgresql starting then the app - which then errors:",[240,502,505],{"className":503,"code":504,"language":245,"meta":246},[243],"Cannot connect to app_db:5432\u002F\u003Cunresolved>:5432\n",[248,506,504],{"__ignoreMap":246},[211,508,509],{},"and deeper in the stacktrace:",[240,511,514],{"className":512,"code":513,"language":245,"meta":246},[243],"Caused by: java.net.UnknownHostException: app_db:5432: invalid IPv6 address\n",[248,515,513],{"__ignoreMap":246},[211,517,518],{},"Very strange.",[292,520,522],{"id":521},"prefer-ipv4","Prefer IPv4?",[211,524,525],{},"Some googling suggested that they have had issues with IPv6 in r2dbc-postgresql before - and they suggest setting the following JVM param:",[240,527,529],{"className":270,"code":528,"language":272,"meta":246,"style":246},"-Djava.net.preferIPv4Stack=true\n",[248,530,531],{"__ignoreMap":246},[276,532,533,536,538],{"class":278,"line":279},[276,534,535],{"class":282},"-Djava.net.preferIPv4Stack",[276,537,345],{"class":286},[276,539,540],{"class":314},"true\n",[211,542,543],{},"However - the results were exactly the same.",[292,545,547],{"id":546},"workaround","Workaround",[211,549,550],{},"What does seem to work however - is removing the port from the r2dbc URL.",[211,552,553],{},"In application.yml - change:",[240,555,559],{"className":556,"code":557,"language":558,"meta":246,"style":246},"language-yml shiki shiki-themes github-dark","spring:\n  r2dbc:\n    url: r2dbc:pool:postgresql:\u002F\u002F${DB_HOST}:${DB_PORT}\u002Ftest_db\n","yml",[248,560,561,569,576],{"__ignoreMap":246},[276,562,563,566],{"class":278,"line":279},[276,564,565],{"class":401},"spring",[276,567,568],{"class":340},":\n",[276,570,571,574],{"class":278,"line":420},[276,572,573],{"class":401},"  r2dbc",[276,575,568],{"class":340},[276,577,579,582,585],{"class":278,"line":578},3,[276,580,581],{"class":401},"    url",[276,583,584],{"class":340},": ",[276,586,587],{"class":286},"r2dbc:pool:postgresql:\u002F\u002F${DB_HOST}:${DB_PORT}\u002Ftest_db\n",[211,589,590],{},"to",[240,592,594],{"className":556,"code":593,"language":558,"meta":246,"style":246},"spring:\n  r2dbc:\n    url: r2dbc:pool:postgresql:\u002F\u002F${DB_HOST}\u002Ftest_db\n",[248,595,596,602,608],{"__ignoreMap":246},[276,597,598,600],{"class":278,"line":279},[276,599,565],{"class":401},[276,601,568],{"class":340},[276,603,604,606],{"class":278,"line":420},[276,605,573],{"class":401},[276,607,568],{"class":340},[276,609,610,612,614],{"class":278,"line":578},[276,611,581],{"class":401},[276,613,584],{"class":340},[276,615,616],{"class":286},"r2dbc:pool:postgresql:\u002F\u002F${DB_HOST}\u002Ftest_db\n",[211,618,619],{},"Now - we just need to rebuild:",[240,621,623],{"className":270,"code":622,"language":272,"meta":246,"style":246},"mvn package\ndocker build -t test-pg-r2dbc:latest .\n",[248,624,625,631],{"__ignoreMap":246},[276,626,627,629],{"class":278,"line":279},[276,628,283],{"class":282},[276,630,290],{"class":286},[276,632,633,635,637,639,641],{"class":278,"line":420},[276,634,462],{"class":282},[276,636,465],{"class":286},[276,638,468],{"class":314},[276,640,471],{"class":286},[276,642,474],{"class":286},[211,644,645],{},"And run again:",[240,647,648],{"className":270,"code":480,"language":272,"meta":246,"style":246},[248,649,650],{"__ignoreMap":246},[276,651,652,654,656,658,660,662],{"class":278,"line":279},[276,653,311],{"class":282},[276,655,315],{"class":314},[276,657,491],{"class":286},[276,659,321],{"class":286},[276,661,324],{"class":314},[276,663,327],{"class":314},[211,665,666],{},"And this time - it works:",[240,668,670],{"className":386,"code":669,"language":388,"meta":246,"style":246},"app       | YYYY-MM-DD HH:MM:SS.SSS  INFO 1 --- [           main] n.c.testpgr2dbc.TestPgR2dbcApplication   : Sample(id=1, name=Name)\napp       | YYYY-MM-DD HH:MM:SS.SSS  INFO 1 --- [tor-tcp-epoll-1] n.c.testpgr2dbc.TestPgR2dbcApplication   : Sample(id=1, name=Name)\n",[248,671,672,695],{"__ignoreMap":246},[276,673,674,677,679,681,684,687,689,691,693],{"class":278,"line":279},[276,675,676],{"class":340},"app       | YYYY-MM-DD HH:MM:",[276,678,398],{"class":314},[276,680,402],{"class":401},[276,682,683],{"class":314}," 1",[276,685,686],{"class":340}," --- [           main] ",[276,688,408],{"class":314},[276,690,411],{"class":340},[276,692,414],{"class":314},[276,694,417],{"class":340},[276,696,697,699,701,703,705,708,710,712,714,716,718],{"class":278,"line":420},[276,698,676],{"class":340},[276,700,398],{"class":314},[276,702,402],{"class":401},[276,704,683],{"class":314},[276,706,707],{"class":340}," --- [tor-tcp-epoll-",[276,709,414],{"class":314},[276,711,434],{"class":340},[276,713,408],{"class":314},[276,715,411],{"class":340},[276,717,414],{"class":314},[276,719,417],{"class":340},[211,721,722],{},"This does feel like a bug in r2dbc-postgresql - but I'm not entirely sure - this was written trying to work out how r2dbc works - so I am not sure if it is completely correct - but - at least it now works.",[211,724,725],{},"Is it an issue having to use the default port?",[211,727,728],{},"Not really - since I run each application under docker on its own docker network and with a container for each postgres DB (or other DB) so there should be no conflicts.",[730,731,732],"style",{},"html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .s4JwU, html code.shiki .s4JwU{--shiki-default:#85E89D}",{"title":246,"searchDepth":420,"depth":420,"links":734},[735,736,737,738],{"id":294,"depth":420,"text":295},{"id":445,"depth":420,"text":446},{"id":521,"depth":420,"text":522},{"id":546,"depth":420,"text":547},"2022-02-22 10:50 +0100",null,"md","A spring boot app using r2dbc was working fine locally but failing under docker - with \"invalid ipv6 address\"",{},true,"\u002F2022\u002F02\u002F22\u002Fr2dbc-postgresql-invalid-ipv6-address-when-dockerized",{"title":206,"description":213},{"loc":745},"2022\u002F02\u002F22\u002Fr2dbc-postgresql-invalid-ipv6-address-when-dockerized",[462,750,565,751,752,753,754,755],"kotlin","spring boot","postgresql","r2dbc","ipv6","troubleshooting","40XuwMW60UgXy3Ldt4fBErywtqNoTHPL4kSKmmYvZss",1775293006017]