dongza3124 2016-09-08 21:00
浏览 179
已采纳

尝试在运行docker-toolbox的Windows上使用docker-compose在docker容器内运行webpack-dev-server时出现“服务器的空响应”

I am having problems accessing a react container run with docker-compose inside docker-machine. I can curl the webpage inside the container, but I cannot access it inside docker-machine (or on the host's browser for that matter). The backend Golang container can be accessed from docker-machine and from the host's browser (as seen in the snippets, it returns a 404 not found).

In the docker-compose logs everything seems to be running smoothly, webpack-dev-server runs as expected, I just can't access it from outside the container.

I am using docker toolbox for windows.

Best to additionally describe the problem with some snippets.

Docker-compose file:

version: '2'
services:
    postgres:
        image: postgres
        environment:
            - POSTGRES_PASSWORD=postgres
    server:
        build: ./server
        command: gin
        volumes:
            - ./server:/go/src/app
        ports:
            - "8080:3000"
        environment:
            - POSTGRES_PASSWORD=postgres
    client:
        build: ./client
        command: npm start
        volumes:
            - ./client:/usr/src/app
            # mount node_modules as a workaround for it disappearing
            # after adding /client as a mounted folder
            - /usr/src/app/node_modules
        ports:
            - "9000:3000"

Dockerfile for the node container:

FROM node:6.5.0-slim

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/
ENV NODE_ENV development
RUN npm install

Output of the following commands inside docker-machine (default):

docker@default:~$ sudo iptables -t nat -L -n

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DOCKER     all  --  0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
DOCKER     all  --  0.0.0.0/0           !127.0.0.0/8          ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  172.17.0.0/16        0.0.0.0/0
MASQUERADE  all  --  172.19.0.0/16        0.0.0.0/0
MASQUERADE  all  --  172.18.0.0/16        0.0.0.0/0
MASQUERADE  tcp  --  172.19.0.2           172.19.0.2           tcp dpt:3000
MASQUERADE  tcp  --  172.19.0.3           172.19.0.3           tcp dpt:3000

Chain DOCKER (2 references)
target     prot opt source               destination
RETURN     all  --  0.0.0.0/0            0.0.0.0/0
RETURN     all  --  0.0.0.0/0            0.0.0.0/0
RETURN     all  --  0.0.0.0/0            0.0.0.0/0
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:8080 to:172.19.0.2:3000
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:9000 to:172.19.0.3:3000

Here comes the main problem:

docker@default:~$ curl 0.0.0.0:9000

curl: (52) Empty reply from server

docker@default:~$ curl 0.0.0.0:8080

404 page not found

docker@default:~$ docker ps

CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS
           NAMES
f93fd1833de2        goreacttodo_client   "npm start"              32 minutes ago      Up 5 minutes        0.0.0.0:9000->
3000/tcp   goreacttodo_client_1
ff1fa9c33b05        postgres             "/docker-entrypoint.s"   3 days ago          Up 5 minutes        5432/tcp
           goreacttodo_postgres_1
e4581f8e368b        goreacttodo_server   "gin"                    3 days ago          Up 5 minutes        0.0.0.0:8080->
3000/tcp   goreacttodo_server_1

Output of the following commands inside the node container:

root@f93fd1833de2:/usr/src/app# curl localhost:3000

<!doctype html>
<html>
<head>
</head>
<body lang="en">
<div id="react-app"></div>
<script src="/bundle.js" type="text/javascript"></script>
</body></html>

Any help would be greatly appreaciated.

  • 写回答

1条回答 默认 最新

  • douquan1953 2016-09-09 10:30
    关注

    Webpack development server by default listens on localhost only.

    If you want to expose it's port outside of Docker container you need to explicitly specify host to listen to:

    webpack-dev-server --host 0.0.0.0 --port 80

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?
  • ¥15 如何自动更换布娃娃图片上的衣服
  • ¥15 心理学eprime编程