我在访问在 docker-machine 中使用 docker-compose 运行的反应容器时遇到问题。我可以在容器内卷曲网页,但我无法在 docker-machine 内(或在主机的浏览器上)访问它。可以从 docker-machine 和主机的浏览器访问后端 Golang 容器(如代码片段所示,它返回404 not found)。
在 docker-compose 日志中,一切似乎都运行顺利,webpack-dev-server 按预期运行,我只是无法从容器外部访问它。
我正在使用 Windows 的 docker 工具箱。
最好用一些片段另外描述问题。
码头工人撰写文件:
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:
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
在 docker-machine 中输出以下命令(默认):
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
主要问题来了:
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
节点容器内以下命令的输出:
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>
任何帮助将不胜感激。