{"id":5795,"date":"2018-10-07T23:28:02","date_gmt":"2018-10-07T23:28:02","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=5795"},"modified":"2018-10-07T23:28:02","modified_gmt":"2018-10-07T23:28:02","slug":"using-postgres-docker","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/using-postgres-docker\/","title":{"rendered":"Using Postgres in Docker"},"content":{"rendered":"<p>I&#8217;ve been using Postgres in Docker for continuous integration. This allows you to script a long-running data setup script, and allows testing up and down migrations between versions. <\/p>\n<p>Here are the lessons learned:<\/p>\n<ul>\n<li>If you want to publish data with the image, copy the <a href=\"https:\/\/github.com\/docker-library\/postgres\/blob\/master\/9.3\/Dockerfile\">Dockerfile<\/a> for the version of Postgres you use, and comment out the &#8220;VOLUME&#8221; command &#8211; this will force the container to retain the data directory in the image.<\/li>\n<li>In my experience these Dockerfiles break with regularity, so you&#8217;ll need to continuously update yours from the source repository.<\/li>\n<li>If you want to enforce security, your best option is to change the arguments to <a href=\"https:\/\/www.postgresql.org\/docs\/current\/static\/app-initdb.html\">initdb<\/a> in docker-entrypoint.sh (e.g. &#8211;auth=md5 &#8211;auth-host=md5 &#8211;auth-local=md5). This may be necessary if you want to use dblink to connect two databases.<\/li>\n<li>If you use unlogged tables, you&#8217;ll need to shut down the database with &#8220;docker container stop&#8221; before doing &#8220;docker commit&#8221;. Without this, you&#8217;ll lose all data in these tables.<\/li>\n<li>If you use semver, I find it helpful to publish multiple versions of the database (e.g. 1.2.3, 1.2.LATEST, 1.LATEST, LATEST). This allows downstream consumers to relax their requirements &#8211; e.g. in the case of migrations, it may be valuable to test a migration against each point release of a prior snapshot.<\/li>\n","protected":false},"excerpt":{"rendered":"<p>Lessons learned from using Postgres in Docker<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[24],"tags":[173,437],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5795"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=5795"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5795\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=5795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=5795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=5795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}