Load balancer for multiple site in different port without host in docker with traefik
Suppose I have two web service say they are w1
and w2
which are deployed by docker-compose.
Now I want to create multiple container for each of them, and create a load balancer in front of them which can make the services accessed by this:
http://localhost:8880 //for service w1
http://localhost:8888 //for service w2
I have searched, and I got dockercloud-haproxy and nginx-proxy.
However, the former is deprecated, and the later have to be used with hostname to distinguish different service.
It is kind of complicated for set different hosts especially in development environment.
Then I found traefik. Seems like more configurable. This is the config file I used:
version: "3"
services:
w1:
image: jwilder/whoami
labels:
- "traefik.backend=whoami"
- "traefik.protocol=http"
- "traefik.port=8080"
- "traefik.frontend.entryPoints=http_8080"
w2:
build: . # a simple node server which use port 80
labels:
- "traefik.backend=node"
- "traefik.protocol=http"
- "traefik.port=80"
- "traefik.frontend.entryPoints=http_80"
lb:
image: traefik
command: "--docker
--logLevel=DEBUG
--entryPoints='Name:http_80 Address::80'
--entryPoints='Name:http_8080 Address::8080'"
ports:
- 8880:80
- 8888:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
While it still can not meet my requirement.
Is this possible or any other alternative solution?
docker docker-compose traefik
add a comment |
Suppose I have two web service say they are w1
and w2
which are deployed by docker-compose.
Now I want to create multiple container for each of them, and create a load balancer in front of them which can make the services accessed by this:
http://localhost:8880 //for service w1
http://localhost:8888 //for service w2
I have searched, and I got dockercloud-haproxy and nginx-proxy.
However, the former is deprecated, and the later have to be used with hostname to distinguish different service.
It is kind of complicated for set different hosts especially in development environment.
Then I found traefik. Seems like more configurable. This is the config file I used:
version: "3"
services:
w1:
image: jwilder/whoami
labels:
- "traefik.backend=whoami"
- "traefik.protocol=http"
- "traefik.port=8080"
- "traefik.frontend.entryPoints=http_8080"
w2:
build: . # a simple node server which use port 80
labels:
- "traefik.backend=node"
- "traefik.protocol=http"
- "traefik.port=80"
- "traefik.frontend.entryPoints=http_80"
lb:
image: traefik
command: "--docker
--logLevel=DEBUG
--entryPoints='Name:http_80 Address::80'
--entryPoints='Name:http_8080 Address::8080'"
ports:
- 8880:80
- 8888:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
While it still can not meet my requirement.
Is this possible or any other alternative solution?
docker docker-compose traefik
add a comment |
Suppose I have two web service say they are w1
and w2
which are deployed by docker-compose.
Now I want to create multiple container for each of them, and create a load balancer in front of them which can make the services accessed by this:
http://localhost:8880 //for service w1
http://localhost:8888 //for service w2
I have searched, and I got dockercloud-haproxy and nginx-proxy.
However, the former is deprecated, and the later have to be used with hostname to distinguish different service.
It is kind of complicated for set different hosts especially in development environment.
Then I found traefik. Seems like more configurable. This is the config file I used:
version: "3"
services:
w1:
image: jwilder/whoami
labels:
- "traefik.backend=whoami"
- "traefik.protocol=http"
- "traefik.port=8080"
- "traefik.frontend.entryPoints=http_8080"
w2:
build: . # a simple node server which use port 80
labels:
- "traefik.backend=node"
- "traefik.protocol=http"
- "traefik.port=80"
- "traefik.frontend.entryPoints=http_80"
lb:
image: traefik
command: "--docker
--logLevel=DEBUG
--entryPoints='Name:http_80 Address::80'
--entryPoints='Name:http_8080 Address::8080'"
ports:
- 8880:80
- 8888:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
While it still can not meet my requirement.
Is this possible or any other alternative solution?
docker docker-compose traefik
Suppose I have two web service say they are w1
and w2
which are deployed by docker-compose.
Now I want to create multiple container for each of them, and create a load balancer in front of them which can make the services accessed by this:
http://localhost:8880 //for service w1
http://localhost:8888 //for service w2
I have searched, and I got dockercloud-haproxy and nginx-proxy.
However, the former is deprecated, and the later have to be used with hostname to distinguish different service.
It is kind of complicated for set different hosts especially in development environment.
Then I found traefik. Seems like more configurable. This is the config file I used:
version: "3"
services:
w1:
image: jwilder/whoami
labels:
- "traefik.backend=whoami"
- "traefik.protocol=http"
- "traefik.port=8080"
- "traefik.frontend.entryPoints=http_8080"
w2:
build: . # a simple node server which use port 80
labels:
- "traefik.backend=node"
- "traefik.protocol=http"
- "traefik.port=80"
- "traefik.frontend.entryPoints=http_80"
lb:
image: traefik
command: "--docker
--logLevel=DEBUG
--entryPoints='Name:http_80 Address::80'
--entryPoints='Name:http_8080 Address::8080'"
ports:
- 8880:80
- 8888:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
While it still can not meet my requirement.
Is this possible or any other alternative solution?
docker docker-compose traefik
docker docker-compose traefik
asked Jan 2 at 12:51
hguserhguser
12.5k39127236
12.5k39127236
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/"
under w1 and w2. Otherwise it defaults to Host:w1.project_name
.
Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080"
to - "traefik.port=8000"
Thanks, I will have a try.
– hguser
Jan 2 at 13:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006729%2fload-balancer-for-multiple-site-in-different-port-without-host-in-docker-with-tr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/"
under w1 and w2. Otherwise it defaults to Host:w1.project_name
.
Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080"
to - "traefik.port=8000"
Thanks, I will have a try.
– hguser
Jan 2 at 13:50
add a comment |
You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/"
under w1 and w2. Otherwise it defaults to Host:w1.project_name
.
Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080"
to - "traefik.port=8000"
Thanks, I will have a try.
– hguser
Jan 2 at 13:50
add a comment |
You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/"
under w1 and w2. Otherwise it defaults to Host:w1.project_name
.
Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080"
to - "traefik.port=8000"
You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/"
under w1 and w2. Otherwise it defaults to Host:w1.project_name
.
Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080"
to - "traefik.port=8000"
edited Jan 2 at 13:51
answered Jan 2 at 13:38
SiyuSiyu
3,10911231
3,10911231
Thanks, I will have a try.
– hguser
Jan 2 at 13:50
add a comment |
Thanks, I will have a try.
– hguser
Jan 2 at 13:50
Thanks, I will have a try.
– hguser
Jan 2 at 13:50
Thanks, I will have a try.
– hguser
Jan 2 at 13:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006729%2fload-balancer-for-multiple-site-in-different-port-without-host-in-docker-with-tr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown