{"id":145,"date":"2016-12-20T23:40:12","date_gmt":"2016-12-20T22:40:12","guid":{"rendered":"http:\/\/xpam.pl\/blog\/?p=145"},"modified":"2024-04-02T23:52:30","modified_gmt":"2024-04-02T21:52:30","slug":"ojdbc7-in-a-docker-container-prepare-for-trouble","status":"publish","type":"post","link":"https:\/\/xpam.pl\/blog\/?p=145","title":{"rendered":"OJDBC7 in a Docker container? Prepare for trouble"},"content":{"rendered":"<p>Scenario: A JDK8 Docker container using OJDBC7 to connect to the database. Sounds simple enough, what could go wrong?<\/p>\n<p>Simptoms: Connecting to the database randomly takes several minutes, fails with a weird <em>SqlRecoverableException: no more data to read from socket<\/em> or just works fine as if there is no problem.<\/p>\n<p>The same Docker image also works fine on some machine but fails consistently on other.<\/p>\n<p>The reason is <a href=\"http:\/\/www.usn-it.de\/index.php\/2009\/02\/20\/oracle-11g-jdbc-driver-hangs-blocked-by-devrandom-entropy-pool-empty\/\">this<\/a>. Docker is not good at \/dev\/random. Probably even more so if you run it in a VM, since it's double isolated from actual entropy sources (my non scientific observation). For whatever reason, OJDBC defaults to \/dev\/random and this causes a block when connecting to the database due to high probability of \/dev\/random depletion.<\/p>\n<p>Simple solution is to just mount \/dev\/urandom to \/dev\/random inside the Docker, in docker run command:<br \/>\n<code>-v \/dev\/urandom:\/dev\/random<\/code><br \/>\nSo.. if you ever want to use OJDBC inside Docker, remember this flag. It will save lives or at least spare you hours of useless debugging.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"wp-post-signature\">\r\n<br \/>\r\n<br \/>\r\n<img src='https:\/\/xpam.pl\/aaaaff.png' title='Moonie' \/> Cen<br \/>\r\n<a href='https:\/\/github.com\/cen1'>GitHub<\/a><br \/>\r\n<a href='https:\/\/eurobattle.net'>Eurobattle.net<\/a><br \/>\r\n<a href='https:\/\/lagabuse.com'>Lagabuse.com<\/a><br \/>\r\n<a href='https:\/\/bnetdocs.org'>Bnetdocs<\/a><br \/>\r\n<\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>Scenario: A JDK8 Docker container using OJDBC7 to connect to the database. Sounds simple enough, what could go wrong? Simptoms: Connecting to the database randomly takes several minutes, fails with a weird SqlRecoverableException: no more data to read from socket or just works fine as if there is no problem. The same Docker image also [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,3],"tags":[],"class_list":["post-145","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming"],"_links":{"self":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=145"}],"version-history":[{"count":3,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/145\/revisions"}],"predecessor-version":[{"id":514,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/145\/revisions\/514"}],"wp:attachment":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}