我有两个docker-compose和nginx运行的docker容器。 我想运行每个特定的主机路径。 (运行他们自己的它的端口上也将工作对我来说)Docker Compose Containers与nginx上的特定主机路径
http://host/container1
http://host/container2
or
http://host:80
http://host:81
我从我的nginx的模板:https://github.com/jwilder/nginx-proxy/blob/master/nginx.tmpl
我能够分开运行,所以他们运行正常单容器nginx的。 我试着修改location/{ proxy_pass .. }
发送到不同的端口(localhost:80,localhost:81)。
加入到L237 https://github.com/jwilder/nginx-proxy/blob/master/nginx.tmpl
location /container1 {
proxy_pass {{ trim $proto }}://{{ trim $host }};
}
location /container2 {
proxy_pass {{ trim $proto }}://{{ trim $host }}:81;
}
泊坞窗,compose.yml
version: '2'
services:
nginx-container:
image: nginx
container_name: nginx-container
ports:
# "server_host_port:nginx_container_port"
- "80:80"
- "81:81"
volumes:
- /etc/nginx/conf.d
- ./docker-gen/proxy.conf:/etc/nginx/proxy.conf
docker-gen:
image: jwilder/docker-gen
command: -notify-sighup nginx-container -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes_from:
- nginx-container
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./docker-gen/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
container-one:
build: ./container-one
image: docker.repository.testing.com/container-one
# Exposing 8080 for dockergen
expose:
- 8080
environment:
- spring.profiles.active=docker,testing
- nginx.host=nginx-container
- nginx.port=80
- VIRTUAL_HOST=host
links:
- nginx-container
depends_on:
- nginx-container
container-two:
build: ./container-two
image: docker.repository.testing.com/container-two
# Exposing 8080 for dockergen
expose:
- 8080
environment:
- spring.profiles.active=docker,testing
- nginx.host=nginx-container
- nginx.port=81
- VIRTUAL_HOST=host
links:
- nginx-container
- container-one
depends_on:
- nginx-container
- container-one
据我了解: 我有我的容器和一个容器两个运行中是这样的:
container-one -> nginx-container:80
container-two -> nginx-container:81
两者都使用虚拟主机“主机”
所以我应该能够在nginx.tmpl文件来更改“所在地”为指向的主机:端口上的容器
然而,这并不工作... 有时我得到的nginx的欢迎页面有时我得到了503或404
我不知道我失踪或做错了什么。 这是配置这个的正确方法吗?
参考文献: https://github.com/jwilder/nginx-proxy https://gist.github.com/soheilhy/8b94347ff8336d971ad0 https://github.com/nbellocam/sample-site-docker/blob/master/nginx/conf/nginx.conf http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/
如果您需要2个不同的容器,则需要不同的端口或第三个端口充当反向代理。 – n00dl3
每个容器运行在它的端口和nginx是反向代理:)除非我有什么问题... –
我有一个像我的服务器上的设置,我明白这个问题,如果你没有得到帮助,明天早上我会寄给你我的作文。 – n00dl3