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
docker docker-compose docker-swarm docker-networking
|
show 1 more comment
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
docker docker-compose docker-swarm docker-networking
@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, seepacman
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 ofdocker service ls
. Can't reproduce, same version
– Siyu
Nov 22 at 16:06
@Siyu It works viadocker0
anddocker_gwbridge
interfaces. I guess your OS makesdocker0
automatically available. What's your OS? Can you showiptables-save
output?
– x-yuri
Nov 22 at 16:30
|
show 1 more comment
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
docker docker-compose docker-swarm docker-networking
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
docker docker-compose docker-swarm docker-networking
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, seepacman
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 ofdocker service ls
. Can't reproduce, same version
– Siyu
Nov 22 at 16:06
@Siyu It works viadocker0
anddocker_gwbridge
interfaces. I guess your OS makesdocker0
automatically available. What's your OS? Can you showiptables-save
output?
– x-yuri
Nov 22 at 16:30
|
show 1 more comment
@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, seepacman
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 ofdocker service ls
. Can't reproduce, same version
– Siyu
Nov 22 at 16:06
@Siyu It works viadocker0
anddocker_gwbridge
interfaces. I guess your OS makesdocker0
automatically available. What's your OS? Can you showiptables-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
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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%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
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
@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
anddocker_gwbridge
interfaces. I guess your OS makesdocker0
automatically available. What's your OS? Can you showiptables-save
output?– x-yuri
Nov 22 at 16:30