如何使Nginx作为docker服务运行,可从主机访问?

时间:2018-11-22 15:20:33

标签: docker docker-compose docker-swarm docker-networking

不用于生产。我能够在这样的容器中运行nginx:

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

但是使用docker compose无效:

docker-compose.yml

version: '3'

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

然后

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

但是它是这样工作的:

# curl DOCKER0_IP:4001

# curl DOCKER_GWBRIDGE:4001

我正在运行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

0 个答案:

没有答案