Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Traefik reverse proxy-load balancing on stand-alone Docker

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The following brings you how to achieve Traefik reverse proxy-load balancing on stand-alone Docker, hoping to give you some help in practical application. Load balancing involves more things, there are not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

Create a connection network between Traefik and container applications

Sudo docker network create traefik-net

Download Traefik sample configuration file

Wget https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml

Edit the Traefik configuration file

Sudo cp. / traefik.sample.toml. / traefik.toml

Sudo vi. / traefik.toml

Edit the contents of the traefik.toml file:

Debug = false

LogLevel = "ERROR"

DefaultEntryPoints = ["http"]

[entryPoints]

[entryPoints.http]

Address = ": 80"

[retry]

[docker]

Endpoint = "unix:///var/run/docker.sock"

Domain = "docker.localhost"

Watch = true

ExposedByDefault = false

Usebindportip = true

SwarmMode = false

Network = "traefik-net"

Run the Traefik reverse proxy container on the host

Docker runs the Traefik command:

Docker run-d\

-- name traefik\

-p 808014 080\

-p 80:80\

-v $PWD/traefik.toml:/etc/traefik/traefik.toml\

-v / var/run/docker.sock:/var/run/docker.sock\

Traefik

5. Run Docker container application

Run the Docker container application web1:

Docker run-d\

-- name nginx\

-label "traefik.backend=nginx"\

-label "traefik.protocol=http"\

-label "traefik.port=80"\

-label "traefik.docker.network=traefik-net"\

-label "traefik.domain=abc.com"\

-label "traefik.frontend.rule=Host:web1.abc.com"\

-label "traefik.enable=true"\

Nginx

Run the Docker container application web2:

Docker run-d\

-- name httpd\

-label "traefik.backend=httpd"\

-label "traefik.protocol=http"\

-label "traefik.port=80"\

-label "traefik.docker.network=traefik-net"\

-label "traefik.domain=abc.com"\

-label "traefik.frontend.rule=Host:web2.abc.com"\

-label "traefik.enable=true"\

Httpd

Configure the client hosts host file and access the container application through the browser

Modify the C:\ Windows\ System32\ drivers\ etc\ hosts file on the Win7 client computer:

192.168.3.168 web1.abc.com

192.168.3.168 web2.abc.com

Access the container application through a browser on the client computer

Http://web1.abc.com

Http://web2.abc.com

7. View the Traefik management backend

Http://192.168.3.168:8080

Note: when running container applications, there can be no spaces around the equal sign in label!

Attached picture:

00-traefik.toml profile

01-run the Traefik container

02-run web1 and web2 container applications

03-Container in operation

04-Traefik Management backend

05-Traefik Management backend 2

06-visit the website through web1.abc.com

07-visit the website through web2.abc.com

After reading the above about how to implement Traefik reverse proxy-load balancing on stand-alone Docker, if there is anything else you need to know, you can find what you are interested in in the industry information or find our professional and technical engineer to answer it. Technical engineers have more than ten years of experience in the industry.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report