0467.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Step By Step How I Setup My HomeLab Docker Containers</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="How To Setup A Docker Environment,How To Setup A Docker Home Lab,How To Setup A Containerized Home Lab,Docker Made Simple,Docker Made Easy,Home Lab,Self-Hosted,Install Guide,Docker,Containers,Containerization,Home Server,VirtualBox,Pi-Hole,Apache,HTTPD,Guacamole,Heimdall,Portainer,MySQL,PostgreSQL,PhpMyAdmin,PhpPGAdmin,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Step By Step How I Setup My HomeLab Docker Containers">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="03/14/2022 08:48:54 PM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Step By Step How I Setup My HomeLab Docker Containers</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>Installing VirtualBox</h2>
  26. <ol>
  27. <li>Download VirtualBox <a href="https://www.virtualbox.org/wiki/Downloads" target="_blank">Download</a></li>
  28. <li>Download VirtualBox Extension Pack <a href="https://www.virtualbox.org/wiki/Downloads" target="_blank">Download</a></li>
  29. <li>Install VirtualBox, accepting the defaults</li>
  30. <li>Install VirtualBox Extension Pack, accepting the defaults</li>
  31. <li>Launch VirtualBox if it is not already running</li>
  32. </ol>
  33. <h2>Creating TurnKey Core VirtualBox VM</h2>
  34. <ol>
  35. <li>Download the TurnKey Linux Core .ova <a href="https://www.turnkeylinux.org/core" target="_blank">Download</a></li>
  36. <li>In VirtualBox, select File &gt; Import Appliance...</li>
  37. <li>Click the Browse icon &gt; Navigate to and select the downloaded .ova file</li>
  38. <li>Click Next and then Import</li>
  39. <li>Make sure the Turnkey Core VM is selected and click Start &gt; Normal</li>
  40. <li>Once the VM boots, enter a new root password</li>
  41. <li>Select Skip on the TurnKey Backup and Migration screen</li>
  42. <li>Select Skip on the System Notifications screen</li>
  43. <li>Select Install on the Security Updates screen</li>
  44. <li>Note the URLs and IP address for the VM &gt; Press Enter to finish the installation</li>
  45. </ol>
  46. <h2>Installing Docker</h2>
  47. <ol>
  48. <li>Execute the following commands in a terminal:
  49. <div class="codeBlock"># update software repositories<br />
  50. apt update<br />
  51. # install necessary packages for https apt calls<br />
  52. apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common<br />
  53. # add docker GPG key<br />
  54. curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -<br />
  55. # add docker software repository<br />
  56. add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable&quot;<br />
  57. # install docker<br />
  58. apt update<br />
  59. apt install docker-ce docker-ce-cli containerd.io<br />
  60. # create a docker group<br />
  61. groupadd docker<br />
  62. # add the current user to the docker group<br />
  63. usermod -aG docker $USER</div>
  64. </li>
  65. </ol>
  66. <h2>Running Portainer Docker Container</h2>
  67. <ol>
  68. <li>Continue with the following commands in terminal to run Portainer:
  69. <div class="codeBlock"># create a working directory for portainer<br />
  70. mkdir ~/docker/portainer -p<br />
  71. # run the portainer docker container<br />
  72. docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v ~/docker/portainer:/data portainer/portainer-ce</div>
  73. </li>
  74. <li>Once the Portainer container is downloaded and running, open a web browser and navigate to http://DNSorIP:9000</li>
  75. <li>Set an administrator username and password &gt; Click Create user</li>
  76. <li>Click the Docker - Manage the local Docker environment option &gt; Click Connect</li>
  77. <li>Select Networks from the left navigation menu</li>
  78. <li>Click the Add Network button</li>
  79. <li>Complete the Create network form as follows:
  80. <p>Name: container-network<br />
  81. Subnet: 173.27.0.0/16<br />
  82. Gateway: 173.27.0.1</p>
  83. </li>
  84. <li>Click the Create the Network button at the bottom of the page</li>
  85. </ol>
  86. <h2>Adding Additional Docker Containers From Portainer UI</h2>
  87. <ol>
  88. <li>Select Containers from the left navigation menu</li>
  89. <li>For each of the containers listed below, click the Add Container button and complete the Create container form with the values given</li>
  90. </ol>
  91. <h3 style="margin-left: 80px;">Heimdall</h3>
  92. <p style="margin-left: 120px;">Name: heimdall<br />
  93. Image: ghcr.io/linuxserver/heimdall:latest<br />
  94. Ports: 40000 &rarr; 80<br />
  95. Volumes: /config &rarr; /root/docker/heimdall<br />
  96. Env:<br />
  97. PUID: 1000<br />
  98. PGID: 1000<br />
  99. TZ: America/New_York<br />
  100. Restart Policy: Unless Stopped</p>
  101. <h3 style="margin-left: 80px;">MySQL</h3>
  102. <p style="margin-left: 120px;">Name: MySQL<br />
  103. Image: mysql:latest<br />
  104. Ports: 3306 &rarr; 3306<br />
  105. Volumes: /var/lib/mysql &rarr; /root/docker/mysql<br />
  106. Env:<br />
  107. MYSQL_ROOT_PASSWORD: password<br />
  108. Restart Policy: Unless Stopped</p>
  109. <h3 style="margin-left: 80px;">phpMyAdmin</h3>
  110. <p style="margin-left: 120px;">Name: phpMyAdmin<br />
  111. Image: phpmyadmin:latest<br />
  112. Ports: 40001 &rarr; 80<br />
  113. Env:<br />
  114. PMA_HOST: MySQL<br />
  115. Restart Policy: Unless Stopped</p>
  116. <h3 style="margin-left: 80px;">PostgreSQL</h3>
  117. <p style="margin-left: 120px;">Name: postgres<br />
  118. Image: postgres:latest<br />
  119. Ports: 5432 &rarr; 5432<br />
  120. Volumes: /var/lib/postgresql/data &rarr; /root/docker/postgresql/data<br />
  121. Env:<br />
  122. POSTGRES_PASSWORD: postgres<br />
  123. Restart Policy: Unless Stopped</p>
  124. <h3 style="margin-left: 80px;">phpPGAdmin</h3>
  125. <p style="margin-left: 120px;">Name: phpPGAdmin<br />
  126. Image: bitnami/phppgadmin:latest<br />
  127. Ports: 40004 &rarr; 8080<br />
  128. Env:<br />
  129. POSTGRESQL_HOST: postgresql<br />
  130. Restart Policy: Unless Stopped</p>
  131. <h3 style="margin-left: 80px;">Watchtower</h3>
  132. <p style="margin-left: 120px;">Name: watchtower<br />
  133. Image: containrrr/watchtower:latest<br />
  134. Volumes: /var/run/docker.sock &rarr; /var/run/docker.sock<br />
  135. Env:<br />
  136. WATCHTOWER_NOTIFICATION_EMAIL_FROM: watchtower@i12bretro.local<br />
  137. WATCHTOWER_NOTIFICATION_EMAIL_TO: sysadmin@i12bretro.local<br />
  138. WATCHTOWER_NOTIFICATION_EMAIL_SERVER: smtp.i12bretro.local<br />
  139. WATCHTOWER_NOTIFICATIONS: email<br />
  140. WATCHTOWER_NO_STARTUP_MESSAGE: true<br />
  141. Restart Policy: Unless Stopped</p>
  142. <h3 style="margin-left: 80px;">Apache HTTPD</h3>
  143. <p style="margin-left: 120px;">Name: httpd<br />
  144. Image: httpd:alpine<br />
  145. Ports: 80 &rarr; 80<br />
  146. Volumes: /usr/local/apache2/conf &rarr; /root/docker/apache2/conf<br />
  147. Restart Policy: Unless Stopped</p>
  148. <h3 style="margin-left: 80px;">Pi-Hole</h3>
  149. <p style="margin-left: 120px;">Name: pihole<br />
  150. Image: pihole/pihole:latest<br />
  151. Ports: 53 &rarr; 53, 53 &rarr; 53 UDP, 67 &rarr; 67 UDP, 40002 &rarr; 80<br />
  152. Volumes:<br />
  153. /etc/pihole/ &rarr; /root/docker/pihole/etc/<br />
  154. /etc/dnsmasq.d/ &rarr; /root/docker/pihole/dnsmasq.d/<br />
  155. Env:<br />
  156. TZ: America/New_York<br />
  157. WEBPASSWORD: password<br />
  158. Restart Policy: Unless Stopped</p>
  159. <h3 style="margin-left: 80px;">guacd</h3>
  160. <p style="margin-left: 120px;">Name: guacd<br />
  161. Image: guacamole/guacd:latest<br />
  162. Restart Policy: Unless Stopped</p>
  163. <h2>Completing Network Setup</h2>
  164. <ol>
  165. <li>Select Containers from the left navigation menu</li>
  166. <li>Click the MySQL container</li>
  167. <li>Scroll down to the Networks section &gt; Select container-network from the dropdown &gt; Click Join Network</li>
  168. <li>Do the same for the phpMyAdmin, Postgres, phpPGAdmin, guacd and Guacamole containers</li>
  169. </ol>
  170. <h2>Creating Apache HTTPD Reverse Proxy</h2>
  171. <ol>
  172. <li>Run the following command in terminal on the Docker host:
  173. <div class="codeBlock"># copy the httpd.conf from container to host<br />
  174. docker cp httpd:/usr/local/apache2/ /root/docker/apache2<br />
  175. # edit httpd.conf<br />
  176. nano ~/docker/apache2/conf/httpd.conf</div>
  177. </li>
  178. <li>Uncomment the following module lines by removing the #
  179. <p>LoadModule proxy_module modules/mod_proxy.so<br />
  180. LoadModule proxy_connect_module modules/mod_proxy_connect.so<br />
  181. LoadModule proxy_http_module modules/mod_proxy_http.so<br />
  182. LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so</p>
  183. </li>
  184. <li>Paste the following at the bottom of the file
  185. <p><label for="cb_li_866775_32">ProxyPreserveHost On</label></p>
  186. <p><label for="cb_li_866775_32">&lt;Location /guacamole/&gt;<br />
  187. Order allow,deny<br />
  188. Allow from all<br />
  189. ProxyPass http://192.168.0.75:40003/guacamole/ flushpackets=on<br />
  190. ProxyPassReverse http://192.168.0.75:40003/guacamole/<br />
  191. &lt;/Location&gt;</label></p>
  192. <p><label for="cb_li_866775_32">&lt;Location /guacamole/websocket-tunnel&gt;<br />
  193. Order allow,deny<br />
  194. Allow from all<br />
  195. ProxyPass ws://192.168.0.75:40003/guacamole/websocket-tunnel<br />
  196. ProxyPassReverse ws://192.168.0.75:40003/guacamole/websocket-tunnel<br />
  197. &lt;/Location&gt;</label></p>
  198. <p><label for="cb_li_866775_32">&lt;Location /phpmyadmin/&gt;<br />
  199. Order allow,deny<br />
  200. Allow from all<br />
  201. ProxyPass http://192.168.0.75:40001/<br />
  202. ProxyPassReverse http://192.168.0.75:40001/<br />
  203. &lt;/Location&gt;</label></p>
  204. <p><label for="cb_li_866775_32">&lt;Location /phppgadmin/&gt;<br />
  205. Order allow,deny<br />
  206. Allow from all<br />
  207. ProxyPass http://192.168.0.75:40004/<br />
  208. ProxyPassReverse http://192.168.0.75:40004/<br />
  209. &lt;/Location&gt;</label></p>
  210. <p><label for="cb_li_866775_32">&lt;Location /pihole/&gt;<br />
  211. Order allow,deny<br />
  212. Allow from all<br />
  213. ProxyPass http://192.168.0.75:40002/admin/<br />
  214. ProxyPassReverse http://192.168.0.75:40002/admin/<br />
  215. &lt;/Location&gt;</label></p>
  216. <p><label for="cb_li_866775_32">&lt;Location /portainer/&gt;<br />
  217. Order allow,deny<br />
  218. Allow from all<br />
  219. ProxyPass http://192.168.0.75:9000/<br />
  220. ProxyPassReverse http://192.168.0.75:9000/<br />
  221. &lt;/Location&gt;</label></p>
  222. <p><label for="cb_li_866775_32">ProxyPass / http://192.168.0.75:40000/<br />
  223. ProxyPassReverse / http://192.168.0.75:40000/</label></p>
  224. </li>
  225. <li>Press CTRL+O, Enter, CTRL+X to write the changes to httpd.conf</li>
  226. <li>Back in the Portainer UI, select Containers from the left navigation menu</li>
  227. <li>Check the box next to httpd &gt; Click the Restart button</li>
  228. </ol>
  229. </div>
  230. </div>
  231. </body>
  232. </html>