How do I make nginx running as a docker service accessible from the host?











up vote
0
down vote

favorite












Not for production. I was able to run nginx in a container like so:



# docker run --rm -itp 4000:80 nginx
# curl localhost:4000
<outputs welcome page>


But with docker compose it doesn't work:



docker-compose.yml:



version: '3'

services:
nginx:
image: nginx:stable
ports:
- "4001:80"


Then,



# docker stack deploy -c docker-compose.yml s1
# curl localhost:4001
<hangs>


But it works this way:



# curl DOCKER0_IP:4001


or



# curl DOCKER_GWBRIDGE:4001


I'm running Arch Linux.



docker stack ls:



NAME                SERVICES            ORCHESTRATOR
s1 1 Swarm


docker stack ps s1:



ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
s9en6oyoj338 s1_nginx.1 nginx:stable yuri Running Running 13 seconds ago


pacman -Qs docker | sed 'n;d':



local/docker 1:18.09.0-2


docker service ls:



ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
710d1lrq7phh s1_nginx replicated 1/1 nginx:stable *:4001->80/tcp









share|improve this question
























  • @Siyu Sure, it wouldn't let me run the stack otherwise.
    – x-yuri
    Nov 22 at 15:37










  • @Siyu see updated question.
    – x-yuri
    Nov 22 at 15:42










  • @Siyu I believe I'm running the latest version, see pacman output in the question. Can't you reproduce? What version are you running?
    – x-yuri
    Nov 22 at 16:04












  • right, I meant to ask the output of docker service ls. Can't reproduce, same version
    – Siyu
    Nov 22 at 16:06










  • @Siyu It works via docker0 and docker_gwbridge interfaces. I guess your OS makes docker0 automatically available. What's your OS? Can you show iptables-save output?
    – x-yuri
    Nov 22 at 16:30















up vote
0
down vote

favorite












Not for production. I was able to run nginx in a container like so:



# docker run --rm -itp 4000:80 nginx
# curl localhost:4000
<outputs welcome page>


But with docker compose it doesn't work:



docker-compose.yml:



version: '3'

services:
nginx:
image: nginx:stable
ports:
- "4001:80"


Then,



# docker stack deploy -c docker-compose.yml s1
# curl localhost:4001
<hangs>


But it works this way:



# curl DOCKER0_IP:4001


or



# curl DOCKER_GWBRIDGE:4001


I'm running Arch Linux.



docker stack ls:



NAME                SERVICES            ORCHESTRATOR
s1 1 Swarm


docker stack ps s1:



ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
s9en6oyoj338 s1_nginx.1 nginx:stable yuri Running Running 13 seconds ago


pacman -Qs docker | sed 'n;d':



local/docker 1:18.09.0-2


docker service ls:



ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
710d1lrq7phh s1_nginx replicated 1/1 nginx:stable *:4001->80/tcp









share|improve this question
























  • @Siyu Sure, it wouldn't let me run the stack otherwise.
    – x-yuri
    Nov 22 at 15:37










  • @Siyu see updated question.
    – x-yuri
    Nov 22 at 15:42










  • @Siyu I believe I'm running the latest version, see pacman output in the question. Can't you reproduce? What version are you running?
    – x-yuri
    Nov 22 at 16:04












  • right, I meant to ask the output of docker service ls. Can't reproduce, same version
    – Siyu
    Nov 22 at 16:06










  • @Siyu It works via docker0 and docker_gwbridge interfaces. I guess your OS makes docker0 automatically available. What's your OS? Can you show iptables-save output?
    – x-yuri
    Nov 22 at 16:30













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Not for production. I was able to run nginx in a container like so:



# docker run --rm -itp 4000:80 nginx
# curl localhost:4000
<outputs welcome page>


But with docker compose it doesn't work:



docker-compose.yml:



version: '3'

services:
nginx:
image: nginx:stable
ports:
- "4001:80"


Then,



# docker stack deploy -c docker-compose.yml s1
# curl localhost:4001
<hangs>


But it works this way:



# curl DOCKER0_IP:4001


or



# curl DOCKER_GWBRIDGE:4001


I'm running Arch Linux.



docker stack ls:



NAME                SERVICES            ORCHESTRATOR
s1 1 Swarm


docker stack ps s1:



ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
s9en6oyoj338 s1_nginx.1 nginx:stable yuri Running Running 13 seconds ago


pacman -Qs docker | sed 'n;d':



local/docker 1:18.09.0-2


docker service ls:



ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
710d1lrq7phh s1_nginx replicated 1/1 nginx:stable *:4001->80/tcp









share|improve this question















Not for production. I was able to run nginx in a container like so:



# docker run --rm -itp 4000:80 nginx
# curl localhost:4000
<outputs welcome page>


But with docker compose it doesn't work:



docker-compose.yml:



version: '3'

services:
nginx:
image: nginx:stable
ports:
- "4001:80"


Then,



# docker stack deploy -c docker-compose.yml s1
# curl localhost:4001
<hangs>


But it works this way:



# curl DOCKER0_IP:4001


or



# curl DOCKER_GWBRIDGE:4001


I'm running Arch Linux.



docker stack ls:



NAME                SERVICES            ORCHESTRATOR
s1 1 Swarm


docker stack ps s1:



ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
s9en6oyoj338 s1_nginx.1 nginx:stable yuri Running Running 13 seconds ago


pacman -Qs docker | sed 'n;d':



local/docker 1:18.09.0-2


docker service ls:



ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
710d1lrq7phh s1_nginx replicated 1/1 nginx:stable *:4001->80/tcp






docker docker-compose docker-swarm docker-networking






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 16:26

























asked Nov 22 at 15:20









x-yuri

4,69733777




4,69733777












  • @Siyu Sure, it wouldn't let me run the stack otherwise.
    – x-yuri
    Nov 22 at 15:37










  • @Siyu see updated question.
    – x-yuri
    Nov 22 at 15:42










  • @Siyu I believe I'm running the latest version, see pacman output in the question. Can't you reproduce? What version are you running?
    – x-yuri
    Nov 22 at 16:04












  • right, I meant to ask the output of docker service ls. Can't reproduce, same version
    – Siyu
    Nov 22 at 16:06










  • @Siyu It works via docker0 and docker_gwbridge interfaces. I guess your OS makes docker0 automatically available. What's your OS? Can you show iptables-save output?
    – x-yuri
    Nov 22 at 16:30


















  • @Siyu Sure, it wouldn't let me run the stack otherwise.
    – x-yuri
    Nov 22 at 15:37










  • @Siyu see updated question.
    – x-yuri
    Nov 22 at 15:42










  • @Siyu I believe I'm running the latest version, see pacman output in the question. Can't you reproduce? What version are you running?
    – x-yuri
    Nov 22 at 16:04












  • right, I meant to ask the output of docker service ls. Can't reproduce, same version
    – Siyu
    Nov 22 at 16:06










  • @Siyu It works via docker0 and docker_gwbridge interfaces. I guess your OS makes docker0 automatically available. What's your OS? Can you show iptables-save output?
    – x-yuri
    Nov 22 at 16:30
















@Siyu Sure, it wouldn't let me run the stack otherwise.
– x-yuri
Nov 22 at 15:37




@Siyu Sure, it wouldn't let me run the stack otherwise.
– x-yuri
Nov 22 at 15:37












@Siyu see updated question.
– x-yuri
Nov 22 at 15:42




@Siyu see updated question.
– x-yuri
Nov 22 at 15:42












@Siyu I believe I'm running the latest version, see pacman output in the question. Can't you reproduce? What version are you running?
– x-yuri
Nov 22 at 16:04






@Siyu I believe I'm running the latest version, see pacman output in the question. Can't you reproduce? What version are you running?
– x-yuri
Nov 22 at 16:04














right, I meant to ask the output of docker service ls. Can't reproduce, same version
– Siyu
Nov 22 at 16:06




right, I meant to ask the output of docker service ls. Can't reproduce, same version
– Siyu
Nov 22 at 16:06












@Siyu It works via docker0 and docker_gwbridge interfaces. I guess your OS makes docker0 automatically available. What's your OS? Can you show iptables-save output?
– x-yuri
Nov 22 at 16:30




@Siyu It works via docker0 and docker_gwbridge interfaces. I guess your OS makes docker0 automatically available. What's your OS? Can you show iptables-save output?
– x-yuri
Nov 22 at 16:30

















active

oldest

votes











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',
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434004%2fhow-do-i-make-nginx-running-as-a-docker-service-accessible-from-the-host%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434004%2fhow-do-i-make-nginx-running-as-a-docker-service-accessible-from-the-host%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu