{"id":1875,"date":"2020-11-13T14:57:44","date_gmt":"2020-11-13T19:57:44","guid":{"rendered":"https:\/\/mossiso.com\/?p=1875"},"modified":"2020-11-13T16:00:48","modified_gmt":"2020-11-13T21:00:48","slug":"docker-development-environment-for-everyone","status":"publish","type":"post","link":"https:\/\/mossiso.com\/2020\/11\/13\/docker-development-environment-for-everyone\/","title":{"rendered":"Docker Development Environment for Everyone"},"content":{"rendered":"\n<p>One of the biggest challenges when collaborating with others in developing software and websites is setting up the development environment. The good ol &#8220;it works on my machine&#8230;&#8221; problem.<\/p>\n\n\n\n<p>Well, this is no panacea for development, but it does a good job of setting up a basic environment pretty quickly.<\/p>\n\n\n\n<p>You&#8217;re in for a special treat, because I&#8217;m going to show you not one (1), but two (2) different development environments; one for PHP, MySQL, Apache and phpMyAdmin, and one for Python (Flask) and PostgreSQL with pgAdmin. Each of these in a Docker container for ease of use.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Pre-requisites<\/h2>\n\n\n\n<p>For any of this to work, make sure you have <a href=\"https:\/\/www.docker.com\/get-started\" data-type=\"URL\" data-id=\"https:\/\/www.docker.com\/get-              started\">Docker Desktop<\/a> installed and running.<\/p>\n\n\n\n<p>We&#8217;ll be using a terminal application for running some commands, so you&#8217;ll need some familiarity with that too.<\/p>\n\n\n\n<p>Git is used to copy the files from the GitHub repo, but you can also download them as a zip file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"653\" src=\"https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.46.50-PM-1024x653.png\" alt=\"\" class=\"wp-image-1882\" srcset=\"https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.46.50-PM-1024x653.png 1024w, https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.46.50-PM-300x191.png 300w, https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.46.50-PM-768x489.png 768w, https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.46.50-PM-1536x979.png 1536w, https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.46.50-PM-2048x1305.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">PMAMP<\/h2>\n\n\n\n<p>We&#8217;ll tackle the <strong>P<\/strong>hp<strong>M<\/strong>yadmin <strong>A<\/strong>pache <strong>M<\/strong>ysql <strong>P<\/strong>hp (PMAMP) environment first.<\/p>\n\n\n\n<p>After setting this up, we&#8217;ll have a place to put PHP code, a running Apache web server, a MySQL server and a running instance of phpMyAdmin.<\/p>\n\n\n\n<p>The quickest way to get this going is to download the files from this GitHub repo <a href=\"https:\/\/github.com\/ammonshepherd\/pmamp\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/ammonshepherd\/pmamp<\/a><\/p>\n\n\n\n<p><code class=\"wp-block-code\">git clone https:\/\/github.com\/ammonshepherd\/pmamp.git<\/code><\/p>\n\n\n\n<p>Change into that directory.<\/p>\n\n\n\n<p><code class=\"wp-block-code\">cd pmamp<\/code><\/p>\n\n\n\n<p>And start the Docker containers<\/p>\n\n\n\n<p><code class=\"wp-block-code\">docker-compose up -d<\/code><\/p>\n\n\n\n<p>You can view the website at <a href=\"http:\/\/lvh.me\">http:\/\/lvh.me<\/a>. lvh.me is just a nice service that points back to your local machine (127.0.0.1 or localhost). It makes it look like you are using a real domain name.<\/p>\n\n\n\n<p>You can view phpMyAdmin at <a href=\"http:\/\/pma.lvh.me\">http:\/\/pma.lvh.me<\/a>.<\/p>\n\n\n\n<p>You can even use a real domain name. Just edit the docker-compose.yml file. There is a line like this: &nbsp;<\/p>\n\n\n\n<p><code class=\"wp-block-code\">- \"traefik.http.routers.php-apache.rule=Host('lvh.me', 'pmamp.lvh.me', 'example.com')\"<\/code><\/p>\n\n\n\n<p>Just add your domain to the list (or remove the other ones). Each entry must use the backtick, rather than the single quotes. WordPress mangles the backticks, so I am using single quotes here.<\/p>\n\n\n\n<p>Now you just need to let your computer know to redirect all traffic to that domain name to itself.<\/p>\n\n\n\n<p>You&#8217;ll need to edit the \/etc\/hosts file (<a href=\"https:\/\/www.makeuseof.com\/tag\/modify-manage-hosts-file-linux\/\">Linux or Mac<\/a>), or c:\\windows\\system32\\drivers\\etc\\hosts (<a href=\"https:\/\/www.howtogeek.com\/howto\/27350\/beginner-geek-how-to-edit-your-hosts-file\/\">Windows<\/a>). Now you can develop for any domain name right on your computer as if it were using the actual domain name.<\/p>\n\n\n\n<p>Put all of your website files in the &#8216;www&#8217; folder and you&#8217;re ready to develop!<\/p>\n\n\n\n<p>Check the README at <a href=\"https:\/\/github.com\/ammonshepherd\/pmamp\">https:\/\/github.com\/ammonshepherd\/pmamp<\/a> for more details on how it works and things to change.<\/p>\n\n\n\n<p>To stop the services (turn off Apache, MySQL and phpAdmin) run<\/p>\n\n\n\n<p><code class=\"wp-block-code\">docker-compose down <\/code><\/p>\n\n\n\n<p>in the same directory where the docker-compose.yml file lives.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"653\" src=\"https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.43.18-PM-1024x653.png\" alt=\"\" class=\"wp-image-1883\" srcset=\"https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.43.18-PM-1024x653.png 1024w, https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.43.18-PM-300x191.png 300w, https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.43.18-PM-768x489.png 768w, https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.43.18-PM-1536x979.png 1536w, https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.43.18-PM-2048x1305.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">pFp<\/h2>\n\n\n\n<p>The set up for Python (using a Flask app) and PostgreSQL is exactly the same process.<\/p>\n\n\n\n<p>Grab the files from <a href=\"https:\/\/github.com\/ammonshepherd\/pfp\">https:\/\/github.com\/ammonshepherd\/pfp<\/a>.<\/p>\n\n\n\n<p><code class=\"wp-block-code\">git clone https:\/\/github.com\/ammonshepherd\/pfp.git<\/code><\/p>\n\n\n\n<p><code class=\"wp-block-code\">cd pfp<\/code><\/p>\n\n\n\n<p><code class=\"wp-block-code\">docker-compose up -d<\/code><\/p>\n\n\n\n<p>You now have a running Flask app at <a href=\"http:\/\/lvh.me\">http:\/\/lvh.me<\/a>, or <a href=\"http:\/\/pfp.lvh.me\">http:\/\/pfp.lvh.me<\/a> and a running pgAdmin application at <a href=\"http:\/\/pga.lvh.me\">http:\/\/pga.lvh.me<\/a>.<\/p>\n\n\n\n<p>The same trick for custom domain names applies here too.<\/p>\n\n\n\n<p>And also check out the README for more details: <a href=\"https:\/\/github.com\/ammonshepherd\/pfp\">https:\/\/github.com\/ammonshepherd\/pfp<\/a><\/p>\n\n\n\n<p>Follow the same commands above to shutdown the Python, PostgreSQL and pgAdmin containers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the biggest challenges when collaborating with others in developing software and websites is setting up the development environment. The good ol &#8220;it works on my machine&#8230;&#8221; problem. Well, this is no panacea for development, but it does a good job of setting up a basic environment pretty quickly. You&#8217;re in for a special &hellip; <a href=\"https:\/\/mossiso.com\/2020\/11\/13\/docker-development-environment-for-everyone\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Docker Development Environment for Everyone<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1885,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"Docker Development Environment for Everyone. I just finished putting together documentation for creating a PHP, MySQL, phpMyAdmin AND a Python, Flask, PostgreSQL, pgAdmin dev environments. Check it out!","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[3,243,167,9,170],"tags":[315,295,319,321,317,69,318,316,219,314],"class_list":["post-1875","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-howto","category-technical","category-technology","category-websites","tag-docker","tag-docker-compose","tag-flask","tag-local-development","tag-pgadmin","tag-php","tag-phpmyadmin","tag-postgres","tag-python","tag-web-development"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/mossiso.com\/wp-content\/uploads\/2020\/11\/Screen-Shot-2020-11-13-at-2.52.52-PM.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9wosP-uf","_links":{"self":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1875"}],"collection":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/comments?post=1875"}],"version-history":[{"count":30,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1875\/revisions"}],"predecessor-version":[{"id":1920,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1875\/revisions\/1920"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media\/1885"}],"wp:attachment":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media?parent=1875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/categories?post=1875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/tags?post=1875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}