0758.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Running Traefik - HTTP Reverse Proxy and Load Balancer - in Docker</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <meta name="keywords" content="Docker Made Easy,Home Lab,Home Lab Ideas,Install Guide,Self-Hosted,Container,Containerization,Containerize,Docker,Docker Container,Docker How To,Docker Installation Tutorial,Docker Made Simple,Docker Simplified,Traefik,Reverse Proxy,HTTP Proxy,Ubuntu,Linux,Getting Started With Docker,Docker Tutorial,How To,Tutorial,i12bretro">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Running Traefik - HTTP Reverse Proxy and Load Balancer - in Docker">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="07/08/2022 08:23:25 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>Running Traefik - HTTP Reverse Proxy and Load Balancer - in Docker</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>What is Traefik?</h2>
  26. <blockquote><em>Traefik (pronounced traffic) is a modern HTTP reverse proxy and load balancer that makes deploying microservices easy. Traefik integrates with your existing infrastructure components [...] and configures itself automatically and dynamically. Pointing Traefik at your orchestrator should be the only configuration step you need. -<a href="https://github.com/traefik/traefik" target="_blank">https://github.com/traefik/traefik</a></em></blockquote>
  27. <h2>Installing Docker</h2>
  28. <ol>
  29. <li>Log into the Linux based device</li>
  30. <li>Run the following commands in the terminal
  31. <div class="codeBlock"># install prerequisites<br />
  32. sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y<br />
  33. # add docker gpg key<br />
  34. curl -fsSL https://download.docker.com/linux/$(awk -F&#39;=&#39; &#39;/^ID=/{ print $NF }&#39; /etc/os-release)/gpg | sudo apt-key add -<br />
  35. # add docker software repository<br />
  36. sudo add-apt-repository &quot;deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F&#39;=&#39; &#39;/^ID=/{ print $NF }&#39; /etc/os-release) $(lsb_release -cs) stable&quot;<br />
  37. # install docker<br />
  38. sudo apt install docker-ce docker-compose containerd.io -y<br />
  39. # enable and start docker service<br />
  40. sudo systemctl enable docker &amp;&amp; sudo systemctl start docker<br />
  41. # add the current user to the docker group<br />
  42. sudo usermod -aG docker $USER<br />
  43. # reauthenticate for the new group membership to take effect<br />
  44. su - $USER</div>
  45. </li>
  46. </ol>
  47. <h2>Running Traefik</h2>
  48. <ol>
  49. <li>Continue with the following commands in a terminal window
  50. <div class="codeBlock"># create a working directory<br />
  51. mkdir ~/docker/traefik -p<br />
  52. # create and edit config file<br />
  53. nano ~/docker/traefik/traefik.yml</div>
  54. </li>
  55. <li>Paste the following default configuration into traefik.yml, replacing the hostname with the docker host
  56. <p>## traefik.yml</p>
  57. <p># Docker configuration backend<br />
  58. providers:<br />
  59. docker:<br />
  60. defaultRule: &quot;Host(`{{ trimPrefix `/` .Name }}.&lt;% dockerhost.fqdn %&gt;`)&quot;</p>
  61. <p># API and dashboard configuration<br />
  62. api:<br />
  63. insecure: true</p>
  64. </li>
  65. <li>Press CTRL+O, Enter, CTRL+X to write the changes</li>
  66. <li>Continue with the following commands in a terminal window
  67. <div class="codeBlock"># start the traefik container<br />
  68. docker run -d --name=traefik -p 8080:8080 -p 80:80 -v ~/docker/traefik/traefik.yml:/etc/traefik/traefik.yml -v /var/run/docker.sock:/var/run/docker.sock traefik</div>
  69. </li>
  70. <li>Open a web browser and navigate to http://DNSorIP:8080</li>
  71. <li>Welcome to the Traefik web dashboard</li>
  72. </ol>
  73. <h2>Dynamic Container Ingress Testing</h2>
  74. <ol>
  75. <li>Continue with the following commands in a terminal window
  76. <div class="codeBlock"># start a basic whoami web service<br />
  77. docker run -d --name whoami -p 40001:80 traefik/whoami</div>
  78. </li>
  79. <li>Back in the web browser, navigate to whoami.&lt;% docker host %&gt;</li>
  80. <li>The Apache HTTPD server response should be displayed</li>
  81. <li>Back in the Traefik dashboard the new whoami HTTP router should display</li>
  82. <li>Let&#39;s try one more test
  83. <div class="codeBlock"># create an apache2 working directory<br />
  84. mkdir ~/docker/apache2/htdocs -p<br />
  85. # create a test html file<br />
  86. echo &#39;&lt;html&gt;&lt;body&gt;&lt;h1&gt;Hello world&lt;/h1&gt;&lt;h3&gt;Have you subscribed yet?&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;&#39; &gt; ~/docker/apache2/htdocs/index.html<br />
  87. # start a basic apache httpd server<br />
  88. docker run -d --name httpd -p 40002:80 -v ~/docker/apache2/htdocs:/usr/local/apache2/htdocs/ httpd</div>
  89. </li>
  90. <li>Back in the web browser, navigate to httpd.&lt;% docker host %&gt;</li>
  91. <li>The Apache HTTPD server response should be displayed</li>
  92. <li>Back in the Traefik dashboard the new httpd HTTP router should display</li>
  93. </ol>
  94. <p>Documentation: <a href="https://doc.traefik.io/traefik/" target="_blank">https://doc.traefik.io/traefik/</a></p> </div>
  95. </div>
  96. </body>
  97. </html>