我有兩個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