我用这LIB:如何改变nginx的代理设置
https://github.com/jwilder/nginx-proxy
这里是我的搬运工,撰写文件:
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
whoami:
image: jwilder/whoami
environment:
- VIRTUAL_HOST=whoami.local
service1:
image: mynode:1.4
build: .
volumes:
- .:/app
restart: always
environment:
- VIRTUAL_HOST=service1.local
service2:
image: mynodeother:1.3
build: .
volumes:
- .:/app
restart: always
environment:
- VIRTUAL_HOST=service2.local
我加了2个新的节点服务...
我可以这样做:curl -H "Host: service2.local" localhost
并从service2获得响应....
问题是我从中得到什么好处?我怎样才能在80端口上运行service1?
这里是Dockerfile
从服务1:
FROM node:6.9.4
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN npm install nodemon -g
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
如果我像这样登录容器:'docker run -it mynode:1.0/bin/bash'并尝试从某种原因ping其他容器我得到'ping:unknown host'你知道什么是问题吗? – Vladimir
尝试使用服务的名称和VIRTUAL_HOST。如果他们在同一个网络,它应该工作。 另外请确保您拥有最新的Docker版本,其中嵌入式DNS服务器已实施。 – calbertts
它的工作原理时,我使用http req从antoher服务调用服务,但现在当像上面那样手动执行时...另外,如何解决路由问题,例如,如果我有2个不同路由的服务,可以绑定路由自动同一主机? – Vladimir