{"id":170,"date":"2016-01-07T17:35:46","date_gmt":"2016-01-07T16:35:46","guid":{"rendered":"https:\/\/blog.mi.hdm-stuttgart.de\/?p=170"},"modified":"2023-06-07T11:32:32","modified_gmt":"2023-06-07T09:32:32","slug":"more-docker-more-power-part-2-setting-up-nginx-and-docker","status":"publish","type":"post","link":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2016\/01\/07\/more-docker-more-power-part-2-setting-up-nginx-and-docker\/","title":{"rendered":"More docker = more power? \u2013 Part 2: Setting up Nginx and Docker"},"content":{"rendered":"<p>This is Part 2 of a series of posts. You can find Part 1 here:&nbsp;<a href=\"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2016\/01\/03\/more-docker-more-power-part-1-setting-up-virtualbox\/\">https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2016\/01\/03\/more-docker-more-power-part-1-setting-up-virtualbox\/<\/a><\/p>\n<p>In the first part of this series we have set up two VirtualBox machines. One functions as the load balancer and the other will house our services. As the next step we want to install docker on the service VM. To do that enter the following commands in the bash:<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">$ wget -qO- https:\/\/get.docker.com\/ | sh\n$ sudo gpasswd -a &lt;username&gt; docker\n$ newgrp docker<\/pre>\n<p>This downloads and installs Docker, adds your user to the docker user group and logs you into this new group to allow you to create and run containers.<\/p>\n<p><!--more-->Since we want to host our test website using nginx we will create a representation of the needed file system in our home directory. We create a directorystructure&nbsp;which looks like a normal Unix filesystem. This filesystem will be copied to our Docker container.<br \/>\nFor example if we create a file called \u201cetc\/foobar\u201d this file will be copied to \u201c\/etc\u201d in our Container. This way we are able to configure everything or add new files, just by putting them in our fake-filesystem.<br \/>\nFirst create a workspace directory, where you put your Dockerfiles and all docker related stuff. In this folder you can create the fake-fs.<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">$ mkdir \/fs\n$ cd fs\n$ mkdir -p etc\/nginx\n$ mkdir -p var\/www\/html<\/pre>\n<p>In our file system we created the folders \u201c\/etc\/nginx\u201d where we\u2019ll put our customized nginx configuration, and \u201c\/var\/www\/html\u201d where we\u2019ll put the test website.<\/p>\n<p>You can create this website directly in your VM &nbsp;or upload it with your favorite tool, like SCP. &nbsp;Simply ensure you put the website in the var\/www\/html directory of your fake-filesystem.<\/p>\n<p>Next, we want to add a nginx.conf config to fs\/etc\/nginx\/. You can use our Configfile we provied via Pastebin (http:\/\/pastebin.com\/ZUq6YyRr) Or you can also use the default config of nginx. But keep in mind you have to use the daemon off; parameter to keep nginx running in the foreground.<\/p>\n<p>After we moved our testwebsite to the fake-filesystem we are ready to deploy it and serve it in a container. Therefore, we create a Dockerfile<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">$ vi Dockerfile<\/pre>\n<p>and enter the following commands:<\/p>\n<pre class=\"prettyprint lang-dockerfile\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">FROM ubuntu:latest\nRUN apt-get -y update &amp;&amp; apt-get install -y nginx\nCOPY fs \/\nRUN chmod -R 755 \/var\/www\/\nRUN chown -R www-data:www-data \/var\/www\/\nCMD nginx<\/pre>\n<p>This creates a new Docker image using Ubuntu as its base, installs nginx, copies all of our files from fs into its root directory, set read\/write rights and starts nginx. Keep in mind the Dockerfile needs to be next to your fake-fs. Your directorystructure should look like the this:<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">.\n+-- Dockerfile\n+-- fs\n    +-- etc\n        +-- nginx\n            +-- nginx.conf\n    +-- var\n        +-- www\n            +-- html\n                +-- index.html<\/pre>\n<p>To create a container from the newly created Dockerfile and run a container from it you can use this two commands:<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">docker build -t testwebsite:1 .\ndocker run -d -p 80:80 testwebsite:1<\/pre>\n<p>The first one creates an Dockerimage from the Dockerfile in the current directory and calls it testwebsite with the versionnumber 1. The second command creates a container from the given image and runs it in background. The port 80 of the container is mapped to port 80 of your VM.<\/p>\n<p>If you now open your browser and enter the IP of your VM you should see your wonderful testwebsite.<\/p>\n<p>The <a href=\"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2016\/02\/07\/more-docker-more-power-part-3-setting-up-the-loadbalancer\/\" target=\"_blank\" rel=\"noopener\">next part <\/a>will explain how to create a loadbalancer and automate the creation of multiple containers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is Part 2 of a series of posts. You can find Part 1 here:&nbsp;https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2016\/01\/03\/more-docker-more-power-part-1-setting-up-virtualbox\/ In the first part of this series we have set up two VirtualBox machines. One functions as the load balancer and the other will house our services. As the next step we want to install docker on the service VM. [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":182,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[651,2,657],"tags":[3,4,11,12,10],"ppma_author":[689],"class_list":["post-170","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-system-designs","category-system-engineering","category-teaching-and-learning","tag-docker","tag-linux","tag-loadbalancing","tag-nginx","tag-virtualbox"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png","jetpack-related-posts":[{"id":149,"url":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2016\/01\/03\/more-docker-more-power-part-1-setting-up-virtualbox\/","url_meta":{"origin":170,"position":0},"title":"More docker = more power? \u2013 Part 1: Setting up VirtualBox","author":"Tobias Schneider","date":"3. January 2016","format":false,"excerpt":"This series of blogposts will focus on the effects on response times when performing different tasks running on a variable number of docker containers in a virtual machine. What will be the performance differences running a small or large number of containers on the same machine? These posts will function\u2026","rel":"","context":"In &quot;System Designs&quot;","block_context":{"text":"System Designs","link":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/category\/system-designs\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":21064,"url":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2021\/09\/11\/how-do-you-get-a-web-application-into-the-cloud\/","url_meta":{"origin":170,"position":1},"title":"How do you get a web application into the cloud?","author":"af094","date":"11. September 2021","format":false,"excerpt":"by Dominik Ratzel (dr079) and Alischa Fritzsche (af094) For the lecture \"Software Development for Cloud Computing\", we set ourselves the goal of exploring new things and gaining experience. We focused on one topic: \"How do you get a web application into the cloud?\". In doing so, we took a closer\u2026","rel":"","context":"In &quot;Cloud Technologies&quot;","block_context":{"text":"Cloud Technologies","link":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/category\/scalable-systems\/cloud-technologies\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2021\/09\/availableRunners-150x118.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":274,"url":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2016\/02\/07\/more-docker-more-power-part-3-setting-up-the-loadbalancer\/","url_meta":{"origin":170,"position":2},"title":"More docker = more power? \u2013 Part 3: Setting up the loadbalancer","author":"Moritz Lottermann","date":"7. February 2016","format":false,"excerpt":"To benefit from using a loadbalancer we need several machines to distribute the traffic on, evidently. Thanks to Docker we simply run docker run -d -p 81:80 testwebsite:1 to get a second machine. This time the container port of the webserver is mapped to port 81. If you now visit\u2026","rel":"","context":"In &quot;Allgemein&quot;","block_context":{"text":"Allgemein","link":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/category\/allgemein\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":293,"url":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2016\/02\/14\/more-docker-more-power-part-4-problems-arise\/","url_meta":{"origin":170,"position":3},"title":"More docker = more power? \u2013 Part 4: Problems arise","author":"Tobias Schneider","date":"14. February 2016","format":false,"excerpt":"Now, it\u2019s finally time to start our first load test. We will be using ApacheBench. To install it simply enter apt-get install apache2-utils. To load test your website enter ab -n 200 -c 50 <URL_to_your_page> This command runs 200 requests, with a maximum of 50 at the same time. The\u2026","rel":"","context":"In &quot;Allgemein&quot;","block_context":{"text":"Allgemein","link":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/category\/allgemein\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2016\/01\/1429543497dockerimg.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3314,"url":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2018\/03\/28\/continuous-integration-deployment-for-a-cross-platform-application-part-1\/","url_meta":{"origin":170,"position":4},"title":"Continuous Integration &#038; Deployment for a Cross-Platform Application &#8211; Part 1","author":"Tobias Eberle, Marco Maisel, Tobias Staib, Mario Walz","date":"28. March 2018","format":false,"excerpt":"When we started the project \"Flora CI\" for the lecture \"System Engineering\", we planned to deal with Continuous Integration. As an important aspect of software engineering all of us have previously been involved in projects where code of developers had to be merged and builds had to be automated somehow.\u2026","rel":"","context":"In &quot;DevOps&quot;","block_context":{"text":"DevOps","link":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/category\/scalable-systems\/devops\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2018\/03\/flora-app.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2018\/03\/flora-app.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2018\/03\/flora-app.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2018\/03\/flora-app.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2018\/03\/flora-app.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2018\/03\/flora-app.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1924,"url":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/2017\/02\/28\/microservices-legolizing-software-development-4\/","url_meta":{"origin":170,"position":5},"title":"Microservices \u2013 Legolizing Software Development IV","author":"Calieston Varatharajah, Christof Kost, Korbinian Kuhn, Marc Schelling, Steffen Mauser","date":"28. February 2017","format":false,"excerpt":"An automated development environment will save you. We explain how we set up Jenkins, Docker and Git to work seamlessly together.","rel":"","context":"In &quot;System Designs&quot;","block_context":{"text":"System Designs","link":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/category\/system-designs\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2017\/02\/draw_io_docker_small-1024x439.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2017\/02\/draw_io_docker_small-1024x439.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/blog.mi.hdm-stuttgart.de\/wp-content\/uploads\/2017\/02\/draw_io_docker_small-1024x439.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"authors":[{"term_id":689,"user_id":9,"is_guest":0,"slug":"ml106","display_name":"Moritz Lottermann","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/4297127a3920bb2d4f850630d30bdfd6a438f4cfee9730be28763772ffc90088?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":16,"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":24646,"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/posts\/170\/revisions\/24646"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/media\/182"}],"wp:attachment":[{"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/tags?post=170"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mi.hdm-stuttgart.de\/index.php\/wp-json\/wp\/v2\/ppma_author?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}