Site update

This commit is contained in:
CronyAkatsuki 2024-01-19 17:36:45 +01:00
parent 60de6575e1
commit 87ecb3e7e0
3 changed files with 49 additions and 49 deletions

View File

@ -6,7 +6,7 @@ draft = false
Do you use docker? Do you use nginx or apachi to proxy the container? Fear not you won't be needing them anymore once you are done with this tutorial. Do you use docker? Do you use nginx or apachi to proxy the container? Fear not you won't be needing them anymore once you are done with this tutorial.
Traefik is a simple docker centric proxy manager that is amazing and allows you to easilly proxy you docker container's with just a couple of label's. Traefik is a simple docker centric proxy manager that is amazing and allows you to easilly proxy you docker containers with just a couple of labels.
<!---more---> <!---more--->
@ -48,7 +48,7 @@ What we are doing here is binding the needed configuration files, the docker soc
We are also forcing it to use the latest available stable image to make sure there are no bugs, and disabling proxying the traefik image itself io the lables to make sure it isn't exposed by any means. We are also forcing it to use the latest available stable image to make sure there are no bugs, and disabling proxying the traefik image itself io the lables to make sure it isn't exposed by any means.
We are also making it so it can restart itself unless we specifically stop it, and binding it to port 80 and 443 because those are the default http and https port's that every browser uses when connecting. We are also making it so it can restart itself unless we specifically stop it, and binding it to port 80 and 443 because those are the default http and https ports that every browser uses when connecting.
## traefik.toml ## traefik.toml
@ -81,7 +81,7 @@ We are also making it so it can restart itself unless we specifically stop it, a
watch = true watch = true
``` ```
In the entryPoint's we are defining the http and https port's and forcing http to redirect to https. In the entryPoints we are defining the http and https ports and forcing http to redirect to https.
In the api section we are enabling the dashboard, but disallowing insecure access to it. In the api section we are enabling the dashboard, but disallowing insecure access to it.
@ -106,7 +106,7 @@ In the rest of the config we are defining the mail and storage for tls certific
Here we are defining the basic auth credentials and routing the monitor domain to the dashboard with basic auth credentials and https. Here we are defining the basic auth credentials and routing the monitor domain to the dashboard with basic auth credentials and https.
Make sure to subsitute the string in qutes for users with what you get generated with httpasswd command: `htpasswd -nb somebody secure_password`. Make sure to subsitute the string in qutes for users with what you get generated with httpasswd command: `htpasswd -n somebody`.
## acme.toml ## acme.toml
@ -114,17 +114,17 @@ To create `acme.toml` run this command `touch acme.toml && chmod 600 acme.toml`
## docker web network ## docker web network
You might have seen the networks part in the docker compose, we need to create it to make other docker container's in different docker compose files be accessible to traefik so it can proxy to them. You might have seen the networks part in the docker compose, we need to create it to make other docker containers in different docker compose files be accessible to traefik so it can proxy to them.
To create it we just need to run `docker network create web` and we are done. To create it we just need to run `docker network create web` and we are done.
--- ---
After all this is done, we can just run `docker compose up -d` and if everyting was setup correctly, running `docker compose logs -f` shouldn't show any error's. After all this is done, we can just run `docker compose up -d` and if everyting was setup correctly, running `docker compose logs -f` shouldn't show any errors.
# Using trafik to proxy to docker container's # Using trafik to proxy to docker containers
Now I'm going to explain to you how to use traefik to proxy to docker container's by using labels. For that I will be using ntfy docker image as an example. Now I'm going to explain to you how to use traefik to proxy to docker containers by using labels. For that I will be using ntfy docker image as an example.
> docker-compose.yml > docker-compose.yml
@ -164,15 +164,15 @@ networks:
The important part's of this docker compose are the following: The important part's of this docker compose are the following:
- ## No exposing port's - ## No exposing ports
As you can see, with traefik you don't need to expose port's from the container making it a lot more secure as it can directly proxy to them from itself using the web network. As you can see, with traefik you don't need to expose port's from the container making it a lot more secure as it can directly proxy to them from itself using the web network.
- ## labels - ## labels
In labels we are defining the host domain we wan't to proxy to our container, we are also enabled tls and with entrypoint's making the container only acessible from https, making it impossible to be accessible with http no matter what. In labels we are defining the host domain we wan't to proxy to our container, we are also enabled tls and with entrypoints making the container only acessible from https, making it impossible to be accessible with http no matter what.
We are also defining the certresolver to be lets-encrypt and setting the port from the container that traefik need's to proxy to 80, this port can be differen't depending on what you wan't to proxy. We are also defining the certresolver to be lets-encrypt and setting the port from the container that traefik needs to proxy to 80, this port can be different depending on what you want to proxy.
- ## networks - ## networks
@ -184,11 +184,11 @@ After you have accustomed the config to what you need, you can just `docker comp
# Disabling traefik # Disabling traefik
Next I will be talkling about how to disable traefik for container's because you don't want it to work for container's you don't want accessible over the network. Next I will be talkling about how to disable traefik for containers because you don't want it to work for containers you dont want accessible over the network.
## Disabling for one service docker-compose ## Disabling for one service docker-compose
As the main example, I have a watchtower instance that I don't wan't proxied to the outside world. To do that we just add `traefik.enable=false` to the labels and trafik will stop being naughty. As the main example, I have a watchtower instance that I dont wan't proxied to the outside world. To do that we just add `traefik.enable=false` to the labels and trafik will stop being naughty.
> example > example
```yaml ```yaml
@ -202,7 +202,7 @@ Take note that for this kind of docker-compose files, networks part IS NOT NEEDE
## Disabling for more complex docker-compose ## Disabling for more complex docker-compose
Now here comes the more tricky part, disabling it for only specific docker containers, and making it so traefik can't access them from it's network. To accomplish that we will use the `traefik.enable=false` label once again, and make use of multiple networks to make sure traefik can only access the web interfaces and keep other containers secure like databases and only accessible to the web interfaces. Now here comes the more tricky part, disabling it for only specific docker containers, and making it so traefik cant access them from its network. To accomplish that we will use the `traefik.enable=false` label once again, and make use of multiple networks to make sure traefik can only access the web interfaces and keep other containers secure like databases and only accessible to the web interfaces.
> example docker-compose.yml > example docker-compose.yml
@ -255,8 +255,8 @@ services:
- mysql - mysql
``` ```
Here we can see what I was talking about in action, take note I took this docker compose file from this digital ocean [blog post](https://www.digitalocean.com/community/tutorials/how-to-use-traefik-v2-as-a-reverse-proxy-for-docker-containers-on-ubuntu-20-04#step-3-registering-containers-with-traefik) that explain's it a lot better I could which you can use as a reference if you didn't understand something about what I was talking about. Here we can see what I was talking about in action, take note I took this docker compose file from this digital ocean [blog post](https://www.digitalocean.com/community/tutorials/how-to-use-traefik-v2-as-a-reverse-proxy-for-docker-containers-on-ubuntu-20-04#step-3-registering-containers-with-traefik) that explains it a lot better I could which you can use as a reference if you didnt understand something about what I was talking about.
# Conclusing # Conclusing
I hope that you were able to setup traefik, or if not and were just reading to see what it's all about I hope you had a good read and might have decided to try out traefik in the future. I hope that you were able to setup traefik, or if not and were just reading to see what its all about I hope you had a good read and might have decided to try out traefik in the future.

View File

@ -18,7 +18,7 @@
<guid>https://cronyakatsuki.xyz/blog/setup-trafik/</guid> <guid>https://cronyakatsuki.xyz/blog/setup-trafik/</guid>
<description>&lt;p&gt;Do you use docker? Do you use nginx or apachi to proxy the container? Fear not you won&amp;rsquo;t be needing them anymore once you are done with this tutorial.&lt;/p&gt; <description>&lt;p&gt;Do you use docker? Do you use nginx or apachi to proxy the container? Fear not you won&amp;rsquo;t be needing them anymore once you are done with this tutorial.&lt;/p&gt;
&lt;p&gt;Traefik is a simple docker centric proxy manager that is amazing and allows you to easilly proxy you docker container&amp;rsquo;s with just a couple of label&amp;rsquo;s.&lt;/p&gt; &lt;p&gt;Traefik is a simple docker centric proxy manager that is amazing and allows you to easilly proxy you docker containers with just a couple of labels.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt; &lt;!-- raw HTML omitted --&gt;
&lt;h1 id=&#34;setting-up-traefik&#34;&gt;Setting up Traefik&lt;/h1&gt; &lt;h1 id=&#34;setting-up-traefik&#34;&gt;Setting up Traefik&lt;/h1&gt;
&lt;p&gt;In this part we will setup traefik, with the dashboard enabled and secured with https and a password.&lt;/p&gt; &lt;p&gt;In this part we will setup traefik, with the dashboard enabled and secured with https and a password.&lt;/p&gt;
@ -49,7 +49,7 @@
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#ca9ee6&#34;&gt;external&lt;/span&gt;: &lt;span style=&#34;color:#ef9f76&#34;&gt;true&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#ca9ee6&#34;&gt;external&lt;/span&gt;: &lt;span style=&#34;color:#ef9f76&#34;&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What we are doing here is binding the needed configuration files, the docker socket so traefik can listen to it and automatically proxy the services, and the acme.json which will keep our ssl certificates.&lt;/p&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What we are doing here is binding the needed configuration files, the docker socket so traefik can listen to it and automatically proxy the services, and the acme.json which will keep our ssl certificates.&lt;/p&gt;
&lt;p&gt;We are also forcing it to use the latest available stable image to make sure there are no bugs, and disabling proxying the traefik image itself io the lables to make sure it isn&amp;rsquo;t exposed by any means.&lt;/p&gt; &lt;p&gt;We are also forcing it to use the latest available stable image to make sure there are no bugs, and disabling proxying the traefik image itself io the lables to make sure it isn&amp;rsquo;t exposed by any means.&lt;/p&gt;
&lt;p&gt;We are also making it so it can restart itself unless we specifically stop it, and binding it to port 80 and 443 because those are the default http and https port&amp;rsquo;s that every browser uses when connecting.&lt;/p&gt; &lt;p&gt;We are also making it so it can restart itself unless we specifically stop it, and binding it to port 80 and 443 because those are the default http and https ports that every browser uses when connecting.&lt;/p&gt;
&lt;h2 id=&#34;traefiktoml&#34;&gt;traefik.toml&lt;/h2&gt; &lt;h2 id=&#34;traefiktoml&#34;&gt;traefik.toml&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-toml&#34; data-lang=&#34;toml&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[entryPoints] &lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-toml&#34; data-lang=&#34;toml&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[entryPoints]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [entryPoints.web] &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [entryPoints.web]
@ -77,7 +77,7 @@
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[providers.file] &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[providers.file]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; filename = &lt;span style=&#34;color:#a6d189&#34;&gt;&amp;#34;traefik_dynamic.toml&amp;#34;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; filename = &lt;span style=&#34;color:#a6d189&#34;&gt;&amp;#34;traefik_dynamic.toml&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; watch = &lt;span style=&#34;color:#ef9f76&#34;&gt;true&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; watch = &lt;span style=&#34;color:#ef9f76&#34;&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the entryPoint&amp;rsquo;s we are defining the http and https port&amp;rsquo;s and forcing http to redirect to https.&lt;/p&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the entryPoints we are defining the http and https ports and forcing http to redirect to https.&lt;/p&gt;
&lt;p&gt;In the api section we are enabling the dashboard, but disallowing insecure access to it.&lt;/p&gt; &lt;p&gt;In the api section we are enabling the dashboard, but disallowing insecure access to it.&lt;/p&gt;
&lt;p&gt;In the rest of the config we are defining the mail and storage for tls certificates, and enabled docker provider binded to a web network, and enabled the file provider for the dashboard setup.&lt;/p&gt; &lt;p&gt;In the rest of the config we are defining the mail and storage for tls certificates, and enabled docker provider binded to a web network, and enabled the file provider for the dashboard setup.&lt;/p&gt;
&lt;h2 id=&#34;traefik_dynamictoml&#34;&gt;traefik_dynamic.toml&lt;/h2&gt; &lt;h2 id=&#34;traefik_dynamictoml&#34;&gt;traefik_dynamic.toml&lt;/h2&gt;
@ -94,16 +94,16 @@
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [http.routers.api.tls] &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; [http.routers.api.tls]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; certResolver = &lt;span style=&#34;color:#a6d189&#34;&gt;&amp;#34;lets-encrypt&amp;#34;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; certResolver = &lt;span style=&#34;color:#a6d189&#34;&gt;&amp;#34;lets-encrypt&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here we are defining the basic auth credentials and routing the monitor domain to the dashboard with basic auth credentials and https.&lt;/p&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here we are defining the basic auth credentials and routing the monitor domain to the dashboard with basic auth credentials and https.&lt;/p&gt;
&lt;p&gt;Make sure to subsitute the string in qutes for users with what you get generated with httpasswd command: &lt;code&gt;htpasswd -nb somebody secure_password&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;Make sure to subsitute the string in qutes for users with what you get generated with httpasswd command: &lt;code&gt;htpasswd -n somebody&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;acmetoml&#34;&gt;acme.toml&lt;/h2&gt; &lt;h2 id=&#34;acmetoml&#34;&gt;acme.toml&lt;/h2&gt;
&lt;p&gt;To create &lt;code&gt;acme.toml&lt;/code&gt; run this command &lt;code&gt;touch acme.toml &amp;amp;&amp;amp; chmod 600 acme.toml&lt;/code&gt; and we are done.&lt;/p&gt; &lt;p&gt;To create &lt;code&gt;acme.toml&lt;/code&gt; run this command &lt;code&gt;touch acme.toml &amp;amp;&amp;amp; chmod 600 acme.toml&lt;/code&gt; and we are done.&lt;/p&gt;
&lt;h2 id=&#34;docker-web-network&#34;&gt;docker web network&lt;/h2&gt; &lt;h2 id=&#34;docker-web-network&#34;&gt;docker web network&lt;/h2&gt;
&lt;p&gt;You might have seen the networks part in the docker compose, we need to create it to make other docker container&amp;rsquo;s in different docker compose files be accessible to traefik so it can proxy to them.&lt;/p&gt; &lt;p&gt;You might have seen the networks part in the docker compose, we need to create it to make other docker containers in different docker compose files be accessible to traefik so it can proxy to them.&lt;/p&gt;
&lt;p&gt;To create it we just need to run &lt;code&gt;docker network create web&lt;/code&gt; and we are done.&lt;/p&gt; &lt;p&gt;To create it we just need to run &lt;code&gt;docker network create web&lt;/code&gt; and we are done.&lt;/p&gt;
&lt;hr&gt; &lt;hr&gt;
&lt;p&gt;After all this is done, we can just run &lt;code&gt;docker compose up -d&lt;/code&gt; and if everyting was setup correctly, running &lt;code&gt;docker compose logs -f&lt;/code&gt; shouldn&amp;rsquo;t show any error&amp;rsquo;s.&lt;/p&gt; &lt;p&gt;After all this is done, we can just run &lt;code&gt;docker compose up -d&lt;/code&gt; and if everyting was setup correctly, running &lt;code&gt;docker compose logs -f&lt;/code&gt; shouldn&amp;rsquo;t show any errors.&lt;/p&gt;
&lt;h1 id=&#34;using-trafik-to-proxy-to-docker-containers&#34;&gt;Using trafik to proxy to docker container&amp;rsquo;s&lt;/h1&gt; &lt;h1 id=&#34;using-trafik-to-proxy-to-docker-containers&#34;&gt;Using trafik to proxy to docker containers&lt;/h1&gt;
&lt;p&gt;Now I&amp;rsquo;m going to explain to you how to use traefik to proxy to docker container&amp;rsquo;s by using labels. For that I will be using ntfy docker image as an example.&lt;/p&gt; &lt;p&gt;Now I&amp;rsquo;m going to explain to you how to use traefik to proxy to docker containers by using labels. For that I will be using ntfy docker image as an example.&lt;/p&gt;
&lt;blockquote&gt; &lt;blockquote&gt;
&lt;p&gt;docker-compose.yml&lt;/p&gt; &lt;p&gt;docker-compose.yml&lt;/p&gt;
&lt;/blockquote&gt; &lt;/blockquote&gt;
@ -141,7 +141,7 @@
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The important part&amp;rsquo;s of this docker compose are the following:&lt;/p&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The important part&amp;rsquo;s of this docker compose are the following:&lt;/p&gt;
&lt;ul&gt; &lt;ul&gt;
&lt;li&gt; &lt;li&gt;
&lt;h2 id=&#34;no-exposing-ports&#34;&gt;No exposing port&amp;rsquo;s&lt;/h2&gt; &lt;h2 id=&#34;no-exposing-ports&#34;&gt;No exposing ports&lt;/h2&gt;
&lt;/li&gt; &lt;/li&gt;
&lt;/ul&gt; &lt;/ul&gt;
&lt;p&gt;As you can see, with traefik you don&amp;rsquo;t need to expose port&amp;rsquo;s from the container making it a lot more secure as it can directly proxy to them from itself using the web network.&lt;/p&gt; &lt;p&gt;As you can see, with traefik you don&amp;rsquo;t need to expose port&amp;rsquo;s from the container making it a lot more secure as it can directly proxy to them from itself using the web network.&lt;/p&gt;
@ -150,8 +150,8 @@
&lt;h2 id=&#34;labels&#34;&gt;labels&lt;/h2&gt; &lt;h2 id=&#34;labels&#34;&gt;labels&lt;/h2&gt;
&lt;/li&gt; &lt;/li&gt;
&lt;/ul&gt; &lt;/ul&gt;
&lt;p&gt;In labels we are defining the host domain we wan&amp;rsquo;t to proxy to our container, we are also enabled tls and with entrypoint&amp;rsquo;s making the container only acessible from https, making it impossible to be accessible with http no matter what.&lt;/p&gt; &lt;p&gt;In labels we are defining the host domain we wan&amp;rsquo;t to proxy to our container, we are also enabled tls and with entrypoints making the container only acessible from https, making it impossible to be accessible with http no matter what.&lt;/p&gt;
&lt;p&gt;We are also defining the certresolver to be lets-encrypt and setting the port from the container that traefik need&amp;rsquo;s to proxy to 80, this port can be differen&amp;rsquo;t depending on what you wan&amp;rsquo;t to proxy.&lt;/p&gt; &lt;p&gt;We are also defining the certresolver to be lets-encrypt and setting the port from the container that traefik needs to proxy to 80, this port can be different depending on what you want to proxy.&lt;/p&gt;
&lt;ul&gt; &lt;ul&gt;
&lt;li&gt; &lt;li&gt;
&lt;h2 id=&#34;networks&#34;&gt;networks&lt;/h2&gt; &lt;h2 id=&#34;networks&#34;&gt;networks&lt;/h2&gt;
@ -161,9 +161,9 @@
&lt;hr&gt; &lt;hr&gt;
&lt;p&gt;After you have accustomed the config to what you need, you can just &lt;code&gt;docker compose up -d&lt;/code&gt;, go to your traefik monitor and after some time you will see ntfy addedd to reverse proxying with tls certficate and only accessible from https.&lt;/p&gt; &lt;p&gt;After you have accustomed the config to what you need, you can just &lt;code&gt;docker compose up -d&lt;/code&gt;, go to your traefik monitor and after some time you will see ntfy addedd to reverse proxying with tls certficate and only accessible from https.&lt;/p&gt;
&lt;h1 id=&#34;disabling-traefik&#34;&gt;Disabling traefik&lt;/h1&gt; &lt;h1 id=&#34;disabling-traefik&#34;&gt;Disabling traefik&lt;/h1&gt;
&lt;p&gt;Next I will be talkling about how to disable traefik for container&amp;rsquo;s because you don&amp;rsquo;t want it to work for container&amp;rsquo;s you don&amp;rsquo;t want accessible over the network.&lt;/p&gt; &lt;p&gt;Next I will be talkling about how to disable traefik for containers because you don&amp;rsquo;t want it to work for containers you dont want accessible over the network.&lt;/p&gt;
&lt;h2 id=&#34;disabling-for-one-service-docker-compose&#34;&gt;Disabling for one service docker-compose&lt;/h2&gt; &lt;h2 id=&#34;disabling-for-one-service-docker-compose&#34;&gt;Disabling for one service docker-compose&lt;/h2&gt;
&lt;p&gt;As the main example, I have a watchtower instance that I don&amp;rsquo;t wan&amp;rsquo;t proxied to the outside world. To do that we just add &lt;code&gt;traefik.enable=false&lt;/code&gt; to the labels and trafik will stop being naughty.&lt;/p&gt; &lt;p&gt;As the main example, I have a watchtower instance that I dont wan&amp;rsquo;t proxied to the outside world. To do that we just add &lt;code&gt;traefik.enable=false&lt;/code&gt; to the labels and trafik will stop being naughty.&lt;/p&gt;
&lt;blockquote&gt; &lt;blockquote&gt;
&lt;p&gt;example&lt;/p&gt; &lt;p&gt;example&lt;/p&gt;
&lt;/blockquote&gt; &lt;/blockquote&gt;
@ -173,7 +173,7 @@
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ef9f76&#34;&gt;...&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ef9f76&#34;&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Take note that for this kind of docker-compose files, networks part IS NOT NEEDED, just create the docker compose file as you would usually without having the networks part.&lt;/p&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Take note that for this kind of docker-compose files, networks part IS NOT NEEDED, just create the docker compose file as you would usually without having the networks part.&lt;/p&gt;
&lt;h2 id=&#34;disabling-for-more-complex-docker-compose&#34;&gt;Disabling for more complex docker-compose&lt;/h2&gt; &lt;h2 id=&#34;disabling-for-more-complex-docker-compose&#34;&gt;Disabling for more complex docker-compose&lt;/h2&gt;
&lt;p&gt;Now here comes the more tricky part, disabling it for only specific docker containers, and making it so traefik can&amp;rsquo;t access them from it&amp;rsquo;s network. To accomplish that we will use the &lt;code&gt;traefik.enable=false&lt;/code&gt; label once again, and make use of multiple networks to make sure traefik can only access the web interfaces and keep other containers secure like databases and only accessible to the web interfaces.&lt;/p&gt; &lt;p&gt;Now here comes the more tricky part, disabling it for only specific docker containers, and making it so traefik cant access them from its network. To accomplish that we will use the &lt;code&gt;traefik.enable=false&lt;/code&gt; label once again, and make use of multiple networks to make sure traefik can only access the web interfaces and keep other containers secure like databases and only accessible to the web interfaces.&lt;/p&gt;
&lt;blockquote&gt; &lt;blockquote&gt;
&lt;p&gt;example docker-compose.yml&lt;/p&gt; &lt;p&gt;example docker-compose.yml&lt;/p&gt;
&lt;/blockquote&gt; &lt;/blockquote&gt;
@ -223,9 +223,9 @@
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; - web &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; - web
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#ca9ee6&#34;&gt;depends_on&lt;/span&gt;: &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#ca9ee6&#34;&gt;depends_on&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; - mysql &lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; - mysql
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here we can see what I was talking about in action, take note I took this docker compose file from this digital ocean &lt;a href=&#34;https://www.digitalocean.com/community/tutorials/how-to-use-traefik-v2-as-a-reverse-proxy-for-docker-containers-on-ubuntu-20-04#step-3-registering-containers-with-traefik&#34;&gt;blog post&lt;/a&gt; that explain&amp;rsquo;s it a lot better I could which you can use as a reference if you didn&amp;rsquo;t understand something about what I was talking about.&lt;/p&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here we can see what I was talking about in action, take note I took this docker compose file from this digital ocean &lt;a href=&#34;https://www.digitalocean.com/community/tutorials/how-to-use-traefik-v2-as-a-reverse-proxy-for-docker-containers-on-ubuntu-20-04#step-3-registering-containers-with-traefik&#34;&gt;blog post&lt;/a&gt; that explains it a lot better I could which you can use as a reference if you didnt understand something about what I was talking about.&lt;/p&gt;
&lt;h1 id=&#34;conclusing&#34;&gt;Conclusing&lt;/h1&gt; &lt;h1 id=&#34;conclusing&#34;&gt;Conclusing&lt;/h1&gt;
&lt;p&gt;I hope that you were able to setup traefik, or if not and were just reading to see what it&amp;rsquo;s all about I hope you had a good read and might have decided to try out traefik in the future.&lt;/p&gt; &lt;p&gt;I hope that you were able to setup traefik, or if not and were just reading to see what its all about I hope you had a good read and might have decided to try out traefik in the future.&lt;/p&gt;
</description> </description>
</item> </item>

View File

@ -9,7 +9,7 @@
<title>Setup Trafik</title> <title>Setup Trafik</title>
<meta property="og:title" content="Setup Trafik" /> <meta property="og:title" content="Setup Trafik" />
<meta property="og:description" content="Do you use docker? Do you use nginx or apachi to proxy the container? Fear not you won&rsquo;t be needing them anymore once you are done with this tutorial. <meta property="og:description" content="Do you use docker? Do you use nginx or apachi to proxy the container? Fear not you won&rsquo;t be needing them anymore once you are done with this tutorial.
Traefik is a simple docker centric proxy manager that is amazing and allows you to easilly proxy you docker container&rsquo;s with just a couple of label&rsquo;s. Traefik is a simple docker centric proxy manager that is amazing and allows you to easilly proxy you docker containers with just a couple of labels.
Setting up Traefik In this part we will setup traefik, with the dashboard enabled and secured with https and a password." /> Setting up Traefik In this part we will setup traefik, with the dashboard enabled and secured with https and a password." />
<meta property="og:type" content="article" /> <meta property="og:type" content="article" />
<meta property="og:url" content="https://cronyakatsuki.xyz/blog/setup-trafik/" /><meta property="article:section" content="blog" /> <meta property="og:url" content="https://cronyakatsuki.xyz/blog/setup-trafik/" /><meta property="article:section" content="blog" />
@ -49,7 +49,7 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
</div> </div>
<p>Do you use docker? Do you use nginx or apachi to proxy the container? Fear not you won&rsquo;t be needing them anymore once you are done with this tutorial.</p> <p>Do you use docker? Do you use nginx or apachi to proxy the container? Fear not you won&rsquo;t be needing them anymore once you are done with this tutorial.</p>
<p>Traefik is a simple docker centric proxy manager that is amazing and allows you to easilly proxy you docker container&rsquo;s with just a couple of label&rsquo;s.</p> <p>Traefik is a simple docker centric proxy manager that is amazing and allows you to easilly proxy you docker containers with just a couple of labels.</p>
<!-- raw HTML omitted --> <!-- raw HTML omitted -->
<h1 id="setting-up-traefik">Setting up Traefik</h1> <h1 id="setting-up-traefik">Setting up Traefik</h1>
<p>In this part we will setup traefik, with the dashboard enabled and secured with https and a password.</p> <p>In this part we will setup traefik, with the dashboard enabled and secured with https and a password.</p>
@ -80,7 +80,7 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
</span></span><span style="display:flex;"><span> <span style="color:#ca9ee6">external</span>: <span style="color:#ef9f76">true</span> </span></span><span style="display:flex;"><span> <span style="color:#ca9ee6">external</span>: <span style="color:#ef9f76">true</span>
</span></span></code></pre></div><p>What we are doing here is binding the needed configuration files, the docker socket so traefik can listen to it and automatically proxy the services, and the acme.json which will keep our ssl certificates.</p> </span></span></code></pre></div><p>What we are doing here is binding the needed configuration files, the docker socket so traefik can listen to it and automatically proxy the services, and the acme.json which will keep our ssl certificates.</p>
<p>We are also forcing it to use the latest available stable image to make sure there are no bugs, and disabling proxying the traefik image itself io the lables to make sure it isn&rsquo;t exposed by any means.</p> <p>We are also forcing it to use the latest available stable image to make sure there are no bugs, and disabling proxying the traefik image itself io the lables to make sure it isn&rsquo;t exposed by any means.</p>
<p>We are also making it so it can restart itself unless we specifically stop it, and binding it to port 80 and 443 because those are the default http and https port&rsquo;s that every browser uses when connecting.</p> <p>We are also making it so it can restart itself unless we specifically stop it, and binding it to port 80 and 443 because those are the default http and https ports that every browser uses when connecting.</p>
<h2 id="traefiktoml">traefik.toml</h2> <h2 id="traefiktoml">traefik.toml</h2>
<div class="highlight"><pre tabindex="0" style="color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[entryPoints] <div class="highlight"><pre tabindex="0" style="color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[entryPoints]
</span></span><span style="display:flex;"><span> [entryPoints.web] </span></span><span style="display:flex;"><span> [entryPoints.web]
@ -108,7 +108,7 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
</span></span><span style="display:flex;"><span>[providers.file] </span></span><span style="display:flex;"><span>[providers.file]
</span></span><span style="display:flex;"><span> filename = <span style="color:#a6d189">&#34;traefik_dynamic.toml&#34;</span> </span></span><span style="display:flex;"><span> filename = <span style="color:#a6d189">&#34;traefik_dynamic.toml&#34;</span>
</span></span><span style="display:flex;"><span> watch = <span style="color:#ef9f76">true</span> </span></span><span style="display:flex;"><span> watch = <span style="color:#ef9f76">true</span>
</span></span></code></pre></div><p>In the entryPoint&rsquo;s we are defining the http and https port&rsquo;s and forcing http to redirect to https.</p> </span></span></code></pre></div><p>In the entryPoints we are defining the http and https ports and forcing http to redirect to https.</p>
<p>In the api section we are enabling the dashboard, but disallowing insecure access to it.</p> <p>In the api section we are enabling the dashboard, but disallowing insecure access to it.</p>
<p>In the rest of the config we are defining the mail and storage for tls certificates, and enabled docker provider binded to a web network, and enabled the file provider for the dashboard setup.</p> <p>In the rest of the config we are defining the mail and storage for tls certificates, and enabled docker provider binded to a web network, and enabled the file provider for the dashboard setup.</p>
<h2 id="traefik_dynamictoml">traefik_dynamic.toml</h2> <h2 id="traefik_dynamictoml">traefik_dynamic.toml</h2>
@ -125,16 +125,16 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
</span></span><span style="display:flex;"><span> [http.routers.api.tls] </span></span><span style="display:flex;"><span> [http.routers.api.tls]
</span></span><span style="display:flex;"><span> certResolver = <span style="color:#a6d189">&#34;lets-encrypt&#34;</span> </span></span><span style="display:flex;"><span> certResolver = <span style="color:#a6d189">&#34;lets-encrypt&#34;</span>
</span></span></code></pre></div><p>Here we are defining the basic auth credentials and routing the monitor domain to the dashboard with basic auth credentials and https.</p> </span></span></code></pre></div><p>Here we are defining the basic auth credentials and routing the monitor domain to the dashboard with basic auth credentials and https.</p>
<p>Make sure to subsitute the string in qutes for users with what you get generated with httpasswd command: <code>htpasswd -nb somebody secure_password</code>.</p> <p>Make sure to subsitute the string in qutes for users with what you get generated with httpasswd command: <code>htpasswd -n somebody</code>.</p>
<h2 id="acmetoml">acme.toml</h2> <h2 id="acmetoml">acme.toml</h2>
<p>To create <code>acme.toml</code> run this command <code>touch acme.toml &amp;&amp; chmod 600 acme.toml</code> and we are done.</p> <p>To create <code>acme.toml</code> run this command <code>touch acme.toml &amp;&amp; chmod 600 acme.toml</code> and we are done.</p>
<h2 id="docker-web-network">docker web network</h2> <h2 id="docker-web-network">docker web network</h2>
<p>You might have seen the networks part in the docker compose, we need to create it to make other docker container&rsquo;s in different docker compose files be accessible to traefik so it can proxy to them.</p> <p>You might have seen the networks part in the docker compose, we need to create it to make other docker containers in different docker compose files be accessible to traefik so it can proxy to them.</p>
<p>To create it we just need to run <code>docker network create web</code> and we are done.</p> <p>To create it we just need to run <code>docker network create web</code> and we are done.</p>
<hr> <hr>
<p>After all this is done, we can just run <code>docker compose up -d</code> and if everyting was setup correctly, running <code>docker compose logs -f</code> shouldn&rsquo;t show any error&rsquo;s.</p> <p>After all this is done, we can just run <code>docker compose up -d</code> and if everyting was setup correctly, running <code>docker compose logs -f</code> shouldn&rsquo;t show any errors.</p>
<h1 id="using-trafik-to-proxy-to-docker-containers">Using trafik to proxy to docker container&rsquo;s</h1> <h1 id="using-trafik-to-proxy-to-docker-containers">Using trafik to proxy to docker containers</h1>
<p>Now I&rsquo;m going to explain to you how to use traefik to proxy to docker container&rsquo;s by using labels. For that I will be using ntfy docker image as an example.</p> <p>Now I&rsquo;m going to explain to you how to use traefik to proxy to docker containers by using labels. For that I will be using ntfy docker image as an example.</p>
<blockquote> <blockquote>
<p>docker-compose.yml</p> <p>docker-compose.yml</p>
</blockquote> </blockquote>
@ -172,7 +172,7 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
</span></span></code></pre></div><p>The important part&rsquo;s of this docker compose are the following:</p> </span></span></code></pre></div><p>The important part&rsquo;s of this docker compose are the following:</p>
<ul> <ul>
<li> <li>
<h2 id="no-exposing-ports">No exposing port&rsquo;s</h2> <h2 id="no-exposing-ports">No exposing ports</h2>
</li> </li>
</ul> </ul>
<p>As you can see, with traefik you don&rsquo;t need to expose port&rsquo;s from the container making it a lot more secure as it can directly proxy to them from itself using the web network.</p> <p>As you can see, with traefik you don&rsquo;t need to expose port&rsquo;s from the container making it a lot more secure as it can directly proxy to them from itself using the web network.</p>
@ -181,8 +181,8 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
<h2 id="labels">labels</h2> <h2 id="labels">labels</h2>
</li> </li>
</ul> </ul>
<p>In labels we are defining the host domain we wan&rsquo;t to proxy to our container, we are also enabled tls and with entrypoint&rsquo;s making the container only acessible from https, making it impossible to be accessible with http no matter what.</p> <p>In labels we are defining the host domain we wan&rsquo;t to proxy to our container, we are also enabled tls and with entrypoints making the container only acessible from https, making it impossible to be accessible with http no matter what.</p>
<p>We are also defining the certresolver to be lets-encrypt and setting the port from the container that traefik need&rsquo;s to proxy to 80, this port can be differen&rsquo;t depending on what you wan&rsquo;t to proxy.</p> <p>We are also defining the certresolver to be lets-encrypt and setting the port from the container that traefik needs to proxy to 80, this port can be different depending on what you want to proxy.</p>
<ul> <ul>
<li> <li>
<h2 id="networks">networks</h2> <h2 id="networks">networks</h2>
@ -192,9 +192,9 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
<hr> <hr>
<p>After you have accustomed the config to what you need, you can just <code>docker compose up -d</code>, go to your traefik monitor and after some time you will see ntfy addedd to reverse proxying with tls certficate and only accessible from https.</p> <p>After you have accustomed the config to what you need, you can just <code>docker compose up -d</code>, go to your traefik monitor and after some time you will see ntfy addedd to reverse proxying with tls certficate and only accessible from https.</p>
<h1 id="disabling-traefik">Disabling traefik</h1> <h1 id="disabling-traefik">Disabling traefik</h1>
<p>Next I will be talkling about how to disable traefik for container&rsquo;s because you don&rsquo;t want it to work for container&rsquo;s you don&rsquo;t want accessible over the network.</p> <p>Next I will be talkling about how to disable traefik for containers because you don&rsquo;t want it to work for containers you dont want accessible over the network.</p>
<h2 id="disabling-for-one-service-docker-compose">Disabling for one service docker-compose</h2> <h2 id="disabling-for-one-service-docker-compose">Disabling for one service docker-compose</h2>
<p>As the main example, I have a watchtower instance that I don&rsquo;t wan&rsquo;t proxied to the outside world. To do that we just add <code>traefik.enable=false</code> to the labels and trafik will stop being naughty.</p> <p>As the main example, I have a watchtower instance that I dont wan&rsquo;t proxied to the outside world. To do that we just add <code>traefik.enable=false</code> to the labels and trafik will stop being naughty.</p>
<blockquote> <blockquote>
<p>example</p> <p>example</p>
</blockquote> </blockquote>
@ -204,7 +204,7 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
</span></span><span style="display:flex;"><span><span style="color:#ef9f76">...</span> </span></span><span style="display:flex;"><span><span style="color:#ef9f76">...</span>
</span></span></code></pre></div><p>Take note that for this kind of docker-compose files, networks part IS NOT NEEDED, just create the docker compose file as you would usually without having the networks part.</p> </span></span></code></pre></div><p>Take note that for this kind of docker-compose files, networks part IS NOT NEEDED, just create the docker compose file as you would usually without having the networks part.</p>
<h2 id="disabling-for-more-complex-docker-compose">Disabling for more complex docker-compose</h2> <h2 id="disabling-for-more-complex-docker-compose">Disabling for more complex docker-compose</h2>
<p>Now here comes the more tricky part, disabling it for only specific docker containers, and making it so traefik can&rsquo;t access them from it&rsquo;s network. To accomplish that we will use the <code>traefik.enable=false</code> label once again, and make use of multiple networks to make sure traefik can only access the web interfaces and keep other containers secure like databases and only accessible to the web interfaces.</p> <p>Now here comes the more tricky part, disabling it for only specific docker containers, and making it so traefik cant access them from its network. To accomplish that we will use the <code>traefik.enable=false</code> label once again, and make use of multiple networks to make sure traefik can only access the web interfaces and keep other containers secure like databases and only accessible to the web interfaces.</p>
<blockquote> <blockquote>
<p>example docker-compose.yml</p> <p>example docker-compose.yml</p>
</blockquote> </blockquote>
@ -254,9 +254,9 @@ Setting up Traefik In this part we will setup traefik, with the dashboard enable
</span></span><span style="display:flex;"><span> - web </span></span><span style="display:flex;"><span> - web
</span></span><span style="display:flex;"><span> <span style="color:#ca9ee6">depends_on</span>: </span></span><span style="display:flex;"><span> <span style="color:#ca9ee6">depends_on</span>:
</span></span><span style="display:flex;"><span> - mysql </span></span><span style="display:flex;"><span> - mysql
</span></span></code></pre></div><p>Here we can see what I was talking about in action, take note I took this docker compose file from this digital ocean <a href="https://www.digitalocean.com/community/tutorials/how-to-use-traefik-v2-as-a-reverse-proxy-for-docker-containers-on-ubuntu-20-04#step-3-registering-containers-with-traefik">blog post</a> that explain&rsquo;s it a lot better I could which you can use as a reference if you didn&rsquo;t understand something about what I was talking about.</p> </span></span></code></pre></div><p>Here we can see what I was talking about in action, take note I took this docker compose file from this digital ocean <a href="https://www.digitalocean.com/community/tutorials/how-to-use-traefik-v2-as-a-reverse-proxy-for-docker-containers-on-ubuntu-20-04#step-3-registering-containers-with-traefik">blog post</a> that explains it a lot better I could which you can use as a reference if you didnt understand something about what I was talking about.</p>
<h1 id="conclusing">Conclusing</h1> <h1 id="conclusing">Conclusing</h1>
<p>I hope that you were able to setup traefik, or if not and were just reading to see what it&rsquo;s all about I hope you had a good read and might have decided to try out traefik in the future.</p> <p>I hope that you were able to setup traefik, or if not and were just reading to see what its all about I hope you had a good read and might have decided to try out traefik in the future.</p>
</div> </div>
</main> </main>
<footer> <footer>