How to load balance docker containers running a simple web application?
I have 3 web containers running in a single host. How do I load balance my web containers?
I have 3 web containers running in a single host. How do I load balance my web containers?
Put a load balancer, such as haproxy or nginx can even do the job.
Either way, put the load balancer on the host or on a different server that can access the exposed ports on the containers. Nginx will probably be simpler for your needs.
To setup basic nginx load balancing:
http { upstream myapp1 { server CONTAINER_APP0_IP:PORT; server CONTAINER_APP1_IP:PORT; server CONTAINER_APP2_IP:PORT; } server { listen 80; location / { proxy_pass http://myapp1; } } }
© 2022 - 2024 — McMap. All rights reserved.
docker run
command to allocate more or less CPU and memory to your containers, see docs.docker.com/reference/commandline/cli/#run for the CPU you have-c, --cpu-shares=0 CPU shares (relative weight)
and for the memory-m, --memory="" Memory limit (format: <number><optional unit>, where unit = b, k, m or g)
– Prearrange