[{"data":1,"prerenderedAt":492},["ShallowReactive",2],{"i-lucide:sun-moon":3,"i-lucide:menu":8,"post-\u002Fblog\u002F2022-12-09-running-traefik":10,"surround-\u002Fblog\u002F2022-12-09-running-traefik":475,"i-lucide:arrow-left":486,"i-lucide:sparkles":488,"i-lucide:user":490},{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":7},0,24,false,"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M12 2v2m2.837 12.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715M16 12a4 4 0 0 0-4-4m7-3l-1.256 1.256M20 12h2\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":9},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M4 5h16M4 12h16M4 19h16\"\u002F>",{"id":11,"title":12,"authors":13,"body":16,"date":460,"description":461,"extension":462,"meta":463,"navigation":80,"path":466,"seo":467,"stem":468,"tags":469,"toc":6,"__hash__":474},"blog\u002Fblog\u002F2022-12-09-running-traefik.md","Running Traefik in Docker",[14,15],"gpt","pfarmer",{"type":17,"value":18,"toc":455},"minimark",[19,30,33,36,41,49,261,268,271,279,286,290,293,299,416,423,425,431,438,442,445,448,451],[20,21,22,29],"p",{},[23,24,28],"a",{"href":25,"rel":26},"https:\u002F\u002Ftraefik.io\u002F",[27],"nofollow","Traefik"," is a popular open source edge router and reverse proxy that makes deploying microservices easy. It integrates with Docker and automatically configures SSL certificates via Let's Encrypt.",[20,31,32],{},"In this post, we'll be installing and configuring Traefik on Docker using Docker Compose. We'll also set up a sample website container and secure it with SSL using the integrated Let's Encrypt support.",[20,34,35],{},"To make things more modular, we'll split up the Traefik configuration and website container into separate Docker Compose files. We'll also secure the Traefik web UI by routing it through Traefik itself.",[37,38,40],"h2",{"id":39},"installing-traefik","Installing Traefik",[20,42,43,44,48],{},"First, we need to create a ",[45,46,47],"code",{},"docker-compose.traefik.yml"," file that will define our Traefik service:",[50,51,56],"pre",{"className":52,"code":53,"language":54,"meta":55,"style":55},"language-yaml shiki shiki-themes github-light github-dark-default","version: '3'\n\nservices:\n\n  traefik:\n    image: traefik:v2.2\n    command: --api.insecure=true --providers.docker --log\n    ports:\n      - \"80:80\"\n      - \"443:443\" \n    volumes:\n      - \u002Fvar\u002Frun\u002Fdocker.sock:\u002Fvar\u002Frun\u002Fdocker.sock\n      - traefik-public-certificates:\u002Fcertificates\n    labels:\n      - \"traefik.http.routers.traefik.rule=Host(`traefik.example.com`)\"\n      - \"traefik.http.routers.traefik.entrypoints=websecure\"\n      - \"traefik.http.routers.traefik.tls=true\"\n      - \"traefik.http.services.traefik.loadbalancer.server.port=8080\"\n\nvolumes:\n  traefik-public-certificates:  \n\nnetworks:\n  - proxy\n","yaml","",[45,57,58,75,82,91,96,104,115,126,134,143,154,162,170,178,186,194,202,210,218,223,231,240,245,253],{"__ignoreMap":55},[59,60,63,67,71],"span",{"class":61,"line":62},"line",1,[59,64,66],{"class":65},"sXQ1o","version",[59,68,70],{"class":69},"szmH1",": ",[59,72,74],{"class":73},"sNbzA","'3'\n",[59,76,78],{"class":61,"line":77},2,[59,79,81],{"emptyLinePlaceholder":80},true,"\n",[59,83,85,88],{"class":61,"line":84},3,[59,86,87],{"class":65},"services",[59,89,90],{"class":69},":\n",[59,92,94],{"class":61,"line":93},4,[59,95,81],{"emptyLinePlaceholder":80},[59,97,99,102],{"class":61,"line":98},5,[59,100,101],{"class":65},"  traefik",[59,103,90],{"class":69},[59,105,107,110,112],{"class":61,"line":106},6,[59,108,109],{"class":65},"    image",[59,111,70],{"class":69},[59,113,114],{"class":73},"traefik:v2.2\n",[59,116,118,121,123],{"class":61,"line":117},7,[59,119,120],{"class":65},"    command",[59,122,70],{"class":69},[59,124,125],{"class":73},"--api.insecure=true --providers.docker --log\n",[59,127,129,132],{"class":61,"line":128},8,[59,130,131],{"class":65},"    ports",[59,133,90],{"class":69},[59,135,137,140],{"class":61,"line":136},9,[59,138,139],{"class":69},"      - ",[59,141,142],{"class":73},"\"80:80\"\n",[59,144,146,148,151],{"class":61,"line":145},10,[59,147,139],{"class":69},[59,149,150],{"class":73},"\"443:443\"",[59,152,153],{"class":69}," \n",[59,155,157,160],{"class":61,"line":156},11,[59,158,159],{"class":65},"    volumes",[59,161,90],{"class":69},[59,163,165,167],{"class":61,"line":164},12,[59,166,139],{"class":69},[59,168,169],{"class":73},"\u002Fvar\u002Frun\u002Fdocker.sock:\u002Fvar\u002Frun\u002Fdocker.sock\n",[59,171,173,175],{"class":61,"line":172},13,[59,174,139],{"class":69},[59,176,177],{"class":73},"traefik-public-certificates:\u002Fcertificates\n",[59,179,181,184],{"class":61,"line":180},14,[59,182,183],{"class":65},"    labels",[59,185,90],{"class":69},[59,187,189,191],{"class":61,"line":188},15,[59,190,139],{"class":69},[59,192,193],{"class":73},"\"traefik.http.routers.traefik.rule=Host(`traefik.example.com`)\"\n",[59,195,197,199],{"class":61,"line":196},16,[59,198,139],{"class":69},[59,200,201],{"class":73},"\"traefik.http.routers.traefik.entrypoints=websecure\"\n",[59,203,205,207],{"class":61,"line":204},17,[59,206,139],{"class":69},[59,208,209],{"class":73},"\"traefik.http.routers.traefik.tls=true\"\n",[59,211,213,215],{"class":61,"line":212},18,[59,214,139],{"class":69},[59,216,217],{"class":73},"\"traefik.http.services.traefik.loadbalancer.server.port=8080\"\n",[59,219,221],{"class":61,"line":220},19,[59,222,81],{"emptyLinePlaceholder":80},[59,224,226,229],{"class":61,"line":225},20,[59,227,228],{"class":65},"volumes",[59,230,90],{"class":69},[59,232,234,237],{"class":61,"line":233},21,[59,235,236],{"class":65},"  traefik-public-certificates",[59,238,239],{"class":69},":  \n",[59,241,243],{"class":61,"line":242},22,[59,244,81],{"emptyLinePlaceholder":80},[59,246,248,251],{"class":61,"line":247},23,[59,249,250],{"class":65},"networks",[59,252,90],{"class":69},[59,254,255,258],{"class":61,"line":5},[59,256,257],{"class":69},"  - ",[59,259,260],{"class":73},"proxy\n",[20,262,263,264,267],{},"This exposes port 80 and 443, enables the API and logging, and configures a router and service for the Traefik web UI at ",[45,265,266],{},"traefik.example.com"," using SSL.",[20,269,270],{},"Let's start it up:",[50,272,277],{"className":273,"code":275,"language":276},[274],"language-text","docker-compose -f docker-compose.traefik.yml up -d\n","text",[45,278,275],{"__ignoreMap":55},[20,280,281,282,285],{},"Traefik should now be up and running, with the web UI available at ",[45,283,284],{},"https:\u002F\u002Ftraefik.example.com",".",[37,287,289],{"id":288},"adding-a-sample-website","Adding a Sample Website",[20,291,292],{},"Next, we'll create a Docker Compose file to run a simple website container:",[20,294,295],{},[296,297,298],"strong",{},"docker-compose.web.yml:",[50,300,302],{"className":52,"code":301,"language":54,"meta":55,"style":55},"version: '3'  \n\nservices:\n\n  web:\n    image: nginx:alpine \n    labels:\n      - \"traefik.http.routers.web.rule=Host(`example.com`)\"\n      - \"traefik.http.routers.web.entrypoints=websecure\"\n      - \"traefik.http.routers.web.tls=true\"\n    networks:\n      - proxy\n\nnetworks:\n  proxy:\n    external: true\n",[45,303,304,316,320,326,330,337,348,354,361,368,375,382,388,392,398,405],{"__ignoreMap":55},[59,305,306,308,310,313],{"class":61,"line":62},[59,307,66],{"class":65},[59,309,70],{"class":69},[59,311,312],{"class":73},"'3'",[59,314,315],{"class":69},"  \n",[59,317,318],{"class":61,"line":77},[59,319,81],{"emptyLinePlaceholder":80},[59,321,322,324],{"class":61,"line":84},[59,323,87],{"class":65},[59,325,90],{"class":69},[59,327,328],{"class":61,"line":93},[59,329,81],{"emptyLinePlaceholder":80},[59,331,332,335],{"class":61,"line":98},[59,333,334],{"class":65},"  web",[59,336,90],{"class":69},[59,338,339,341,343,346],{"class":61,"line":106},[59,340,109],{"class":65},[59,342,70],{"class":69},[59,344,345],{"class":73},"nginx:alpine",[59,347,153],{"class":69},[59,349,350,352],{"class":61,"line":117},[59,351,183],{"class":65},[59,353,90],{"class":69},[59,355,356,358],{"class":61,"line":128},[59,357,139],{"class":69},[59,359,360],{"class":73},"\"traefik.http.routers.web.rule=Host(`example.com`)\"\n",[59,362,363,365],{"class":61,"line":136},[59,364,139],{"class":69},[59,366,367],{"class":73},"\"traefik.http.routers.web.entrypoints=websecure\"\n",[59,369,370,372],{"class":61,"line":145},[59,371,139],{"class":69},[59,373,374],{"class":73},"\"traefik.http.routers.web.tls=true\"\n",[59,376,377,380],{"class":61,"line":156},[59,378,379],{"class":65},"    networks",[59,381,90],{"class":69},[59,383,384,386],{"class":61,"line":164},[59,385,139],{"class":69},[59,387,260],{"class":73},[59,389,390],{"class":61,"line":172},[59,391,81],{"emptyLinePlaceholder":80},[59,393,394,396],{"class":61,"line":180},[59,395,250],{"class":65},[59,397,90],{"class":69},[59,399,400,403],{"class":61,"line":188},[59,401,402],{"class":65},"  proxy",[59,404,90],{"class":69},[59,406,407,410,412],{"class":61,"line":196},[59,408,409],{"class":65},"    external",[59,411,70],{"class":69},[59,413,415],{"class":414},"sPgVT","true\n",[20,417,418,419,422],{},"This attaches the web container to the ",[45,420,421],{},"proxy"," network, allowing Traefik to automatically pick it up.",[20,424,270],{},[50,426,429],{"className":427,"code":428,"language":276},[274],"docker-compose -f docker-compose.web.yml up -d\n",[45,430,428],{"__ignoreMap":55},[20,432,433,434,437],{},"Traefik will grab the SSL certificate for ",[45,435,436],{},"example.com"," and route traffic to the web container.",[37,439,441],{"id":440},"conclusion","Conclusion",[20,443,444],{},"With just a few labels, we can easily add containers to Traefik without needing to reconfigure the proxy itself. This makes it easy to deploy new microservices and scale horizontally.",[20,446,447],{},"Securing the Traefik web UI behind its own proxy is a best practice that ensures outside clients can't directly access the dashboard.",[20,449,450],{},"Let me know if you have any other questions!",[452,453,454],"style",{},"html pre.shiki code .sXQ1o, html code.shiki .sXQ1o{--shiki-default:#22863A;--shiki-dark:#7EE787}html pre.shiki code .szmH1, html code.shiki .szmH1{--shiki-default:#24292E;--shiki-dark:#E6EDF3}html pre.shiki code .sNbzA, html code.shiki .sNbzA{--shiki-default:#032F62;--shiki-dark:#A5D6FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sPgVT, html code.shiki .sPgVT{--shiki-default:#005CC5;--shiki-dark:#79C0FF}",{"title":55,"searchDepth":84,"depth":84,"links":456},[457,458,459],{"id":39,"depth":77,"text":40},{"id":288,"depth":77,"text":289},{"id":440,"depth":77,"text":441},"2022-12-09","Traefik is a popular open source edge router and reverse proxy that makes deploying microservices easy. It integrates with Docker and automatically configures SSL certificates via Let's Encrypt.","md",{"type":464,"layout":465},"post","blog_page","\u002Fblog\u002F2022-12-09-running-traefik",{"title":12,"description":461},"blog\u002F2022-12-09-running-traefik",[470,471,472,473],"traefik","docker","sysadmin","devops","bmQTCDAr9Br1WOSiKykt8Beenwg39QQPymL5rV0huHo",[476,481],{"title":477,"path":478,"stem":479,"date":480,"children":-1},"Installing Docker on Debian 11","\u002Fblog\u002F2022-12-01-installing-docker-on-debian","blog\u002F2022-12-01-installing-docker-on-debian","2022-12-01",{"title":482,"path":483,"stem":484,"date":485,"children":-1},"Is a string an anagram?","\u002Fblog\u002F2023-01-14-anagram","blog\u002F2023-01-14-anagram","2023-01-14",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":487},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m12 19l-7-7l7-7m7 7H5\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":489},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594zM20 2v4m2-2h-4\"\u002F>\u003Ccircle cx=\"4\" cy=\"20\" r=\"2\"\u002F>\u003C\u002Fg>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":491},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2\"\u002F>\u003Ccircle cx=\"12\" cy=\"7\" r=\"4\"\u002F>\u003C\u002Fg>",1783616166226]