Docker Compose with static public IP over LAN but different with Host IP
I have the requirement where I need to expose all my containers through a static public IP.
However, the static public IP cannot be host IP because host IP must be dynamic.
The 2 solutions I found is macvlan and linux secondary IP, but base on my understanding, they cannot fulfil my need.
with macvlan, each container will get individual IP. I need to access all container through the same IP.
with linux secondary IP, I can assign a single static IP which exclusive for my docker container. However, I didn't found a way to manage the /etc/network/interface
inside a docker container.
My question is:
- Is it possible to set all container using same ip using macvlan?
- Is there any way to manage
/etc/network/interface
, include ifup and ifdown inside a docker container? - Is there any alternative method
Edit:
the image is the system design for what I wish to achieve:
docker docker-compose
add a comment |
I have the requirement where I need to expose all my containers through a static public IP.
However, the static public IP cannot be host IP because host IP must be dynamic.
The 2 solutions I found is macvlan and linux secondary IP, but base on my understanding, they cannot fulfil my need.
with macvlan, each container will get individual IP. I need to access all container through the same IP.
with linux secondary IP, I can assign a single static IP which exclusive for my docker container. However, I didn't found a way to manage the /etc/network/interface
inside a docker container.
My question is:
- Is it possible to set all container using same ip using macvlan?
- Is there any way to manage
/etc/network/interface
, include ifup and ifdown inside a docker container? - Is there any alternative method
Edit:
the image is the system design for what I wish to achieve:
docker docker-compose
add a comment |
I have the requirement where I need to expose all my containers through a static public IP.
However, the static public IP cannot be host IP because host IP must be dynamic.
The 2 solutions I found is macvlan and linux secondary IP, but base on my understanding, they cannot fulfil my need.
with macvlan, each container will get individual IP. I need to access all container through the same IP.
with linux secondary IP, I can assign a single static IP which exclusive for my docker container. However, I didn't found a way to manage the /etc/network/interface
inside a docker container.
My question is:
- Is it possible to set all container using same ip using macvlan?
- Is there any way to manage
/etc/network/interface
, include ifup and ifdown inside a docker container? - Is there any alternative method
Edit:
the image is the system design for what I wish to achieve:
docker docker-compose
I have the requirement where I need to expose all my containers through a static public IP.
However, the static public IP cannot be host IP because host IP must be dynamic.
The 2 solutions I found is macvlan and linux secondary IP, but base on my understanding, they cannot fulfil my need.
with macvlan, each container will get individual IP. I need to access all container through the same IP.
with linux secondary IP, I can assign a single static IP which exclusive for my docker container. However, I didn't found a way to manage the /etc/network/interface
inside a docker container.
My question is:
- Is it possible to set all container using same ip using macvlan?
- Is there any way to manage
/etc/network/interface
, include ifup and ifdown inside a docker container? - Is there any alternative method
Edit:
the image is the system design for what I wish to achieve:
docker docker-compose
docker docker-compose
edited Jan 2 at 7:29
King Wei Lo
asked Jan 1 at 14:11


King Wei LoKing Wei Lo
167
167
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Assign the static IP to your host and use the ordinary docker run -p
option. The host is allowed to have multiple IP addresses (it presumably already has its dynamic IP address and the Docker-internal 172.17.0.1 address) and you can use an additional parameter to docker run -p 10.10.10.10:80:8888
to bind to a specific host address (that specific address and no other, port 80, forwards to port 8888 in the container).
Another good setup is to provision a load balancer of some sort, assign the static IP address to it, and have it forward to the host. This is also helpful if you want to put some level of rate-limiting or basic HTTP filtering at this layer.
There's no specific technical barrier to running ifconfig
by hand inside a container, but no off-the-shelf images expects to need to do it, which means you'll need to write all of your own images that won't really be reusable outside this specific environment. A developer might have trouble running the identical image locally, for instance.
Just to clarify, basically your answer is similar to my second approach, and additionally bind the container to specific IP?
– King Wei Lo
Jan 1 at 23:55
The containers don't know they're being NATted to a specific static IP address.
– David Maze
Jan 2 at 0:31
Understand, I've uploaded an image and I guess it same with the solution provided by you.
– King Wei Lo
Jan 2 at 8:09
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%2f53996149%2fdocker-compose-with-static-public-ip-over-lan-but-different-with-host-ip%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
Assign the static IP to your host and use the ordinary docker run -p
option. The host is allowed to have multiple IP addresses (it presumably already has its dynamic IP address and the Docker-internal 172.17.0.1 address) and you can use an additional parameter to docker run -p 10.10.10.10:80:8888
to bind to a specific host address (that specific address and no other, port 80, forwards to port 8888 in the container).
Another good setup is to provision a load balancer of some sort, assign the static IP address to it, and have it forward to the host. This is also helpful if you want to put some level of rate-limiting or basic HTTP filtering at this layer.
There's no specific technical barrier to running ifconfig
by hand inside a container, but no off-the-shelf images expects to need to do it, which means you'll need to write all of your own images that won't really be reusable outside this specific environment. A developer might have trouble running the identical image locally, for instance.
Just to clarify, basically your answer is similar to my second approach, and additionally bind the container to specific IP?
– King Wei Lo
Jan 1 at 23:55
The containers don't know they're being NATted to a specific static IP address.
– David Maze
Jan 2 at 0:31
Understand, I've uploaded an image and I guess it same with the solution provided by you.
– King Wei Lo
Jan 2 at 8:09
add a comment |
Assign the static IP to your host and use the ordinary docker run -p
option. The host is allowed to have multiple IP addresses (it presumably already has its dynamic IP address and the Docker-internal 172.17.0.1 address) and you can use an additional parameter to docker run -p 10.10.10.10:80:8888
to bind to a specific host address (that specific address and no other, port 80, forwards to port 8888 in the container).
Another good setup is to provision a load balancer of some sort, assign the static IP address to it, and have it forward to the host. This is also helpful if you want to put some level of rate-limiting or basic HTTP filtering at this layer.
There's no specific technical barrier to running ifconfig
by hand inside a container, but no off-the-shelf images expects to need to do it, which means you'll need to write all of your own images that won't really be reusable outside this specific environment. A developer might have trouble running the identical image locally, for instance.
Just to clarify, basically your answer is similar to my second approach, and additionally bind the container to specific IP?
– King Wei Lo
Jan 1 at 23:55
The containers don't know they're being NATted to a specific static IP address.
– David Maze
Jan 2 at 0:31
Understand, I've uploaded an image and I guess it same with the solution provided by you.
– King Wei Lo
Jan 2 at 8:09
add a comment |
Assign the static IP to your host and use the ordinary docker run -p
option. The host is allowed to have multiple IP addresses (it presumably already has its dynamic IP address and the Docker-internal 172.17.0.1 address) and you can use an additional parameter to docker run -p 10.10.10.10:80:8888
to bind to a specific host address (that specific address and no other, port 80, forwards to port 8888 in the container).
Another good setup is to provision a load balancer of some sort, assign the static IP address to it, and have it forward to the host. This is also helpful if you want to put some level of rate-limiting or basic HTTP filtering at this layer.
There's no specific technical barrier to running ifconfig
by hand inside a container, but no off-the-shelf images expects to need to do it, which means you'll need to write all of your own images that won't really be reusable outside this specific environment. A developer might have trouble running the identical image locally, for instance.
Assign the static IP to your host and use the ordinary docker run -p
option. The host is allowed to have multiple IP addresses (it presumably already has its dynamic IP address and the Docker-internal 172.17.0.1 address) and you can use an additional parameter to docker run -p 10.10.10.10:80:8888
to bind to a specific host address (that specific address and no other, port 80, forwards to port 8888 in the container).
Another good setup is to provision a load balancer of some sort, assign the static IP address to it, and have it forward to the host. This is also helpful if you want to put some level of rate-limiting or basic HTTP filtering at this layer.
There's no specific technical barrier to running ifconfig
by hand inside a container, but no off-the-shelf images expects to need to do it, which means you'll need to write all of your own images that won't really be reusable outside this specific environment. A developer might have trouble running the identical image locally, for instance.
answered Jan 1 at 20:08
David MazeDavid Maze
15k31429
15k31429
Just to clarify, basically your answer is similar to my second approach, and additionally bind the container to specific IP?
– King Wei Lo
Jan 1 at 23:55
The containers don't know they're being NATted to a specific static IP address.
– David Maze
Jan 2 at 0:31
Understand, I've uploaded an image and I guess it same with the solution provided by you.
– King Wei Lo
Jan 2 at 8:09
add a comment |
Just to clarify, basically your answer is similar to my second approach, and additionally bind the container to specific IP?
– King Wei Lo
Jan 1 at 23:55
The containers don't know they're being NATted to a specific static IP address.
– David Maze
Jan 2 at 0:31
Understand, I've uploaded an image and I guess it same with the solution provided by you.
– King Wei Lo
Jan 2 at 8:09
Just to clarify, basically your answer is similar to my second approach, and additionally bind the container to specific IP?
– King Wei Lo
Jan 1 at 23:55
Just to clarify, basically your answer is similar to my second approach, and additionally bind the container to specific IP?
– King Wei Lo
Jan 1 at 23:55
The containers don't know they're being NATted to a specific static IP address.
– David Maze
Jan 2 at 0:31
The containers don't know they're being NATted to a specific static IP address.
– David Maze
Jan 2 at 0:31
Understand, I've uploaded an image and I guess it same with the solution provided by you.
– King Wei Lo
Jan 2 at 8:09
Understand, I've uploaded an image and I guess it same with the solution provided by you.
– King Wei Lo
Jan 2 at 8:09
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%2f53996149%2fdocker-compose-with-static-public-ip-over-lan-but-different-with-host-ip%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