我对this set泊坞窗文件有一个非常奇怪的问题:
docker run将执行我想要的操作,而docker-compose将不会
我和Docker非常相似,因此这可能是一个相当简单的问题 - 我提前道歉!
docker run -p 80:8080 -i -t lakrids_devlakrids
172.17.0.1 - - [01/Feb/2017:23:29:36 +0000] "GET / HTTP/1.1" 200 6979 "-" "curl/7.29.0"
但如果我用docker-compose启动相同的容器,我会得到
docker-compose up devlakrids
Recreating devlakrids
Attaching to devlakrids
devlakrids | 2017/02/01 23:28:19 [emerg] 11#11: host not found in upstream "httpstat.us" in /etc/nginx/nginx.conf:21
devlakrids | nginx: [emerg] host not found in upstream "httpstat.us" in /etc/nginx/nginx.conf:21
devlakrids exited with code 1
答案 0 :(得分:1)
两个可能的罪魁祸首:
nginx
是一个有趣的野兽:如果上游在nginx
已经运行时发生故障,那么nginx
会继续运行。但是,如果nginx
启动时无法访问上游,则后者将无法启动。要解决此问题,您可能需要在启动nginx
之前向您nginx
容器测试添加启动脚本,以便上游启动;
尝试明确添加links
:我们遇到了这个问题,nginx
泊坞窗没有看到通过compose
服务名称隐式定义的其他计算机。
最后,一个真正被遗忘的选项是:您没有在您显示的文件中指定在docker引擎中启动httpstat.us
服务的任何位置,因此实际上令人惊讶的是它在没有撰写的情况下适合您。
答案 1 :(得分:1)
根据描述,您在合成之外运行的图像可能与您在合成中运行的图像不同,或者您有不同的卷安装。要解决您的错误,我将使用上游定义更新您的nginx.conf:
daemon off;
worker_processes 1;
events { worker_connections 1024; }
http {
upstream httpstat.us {
least_conn;
server httpstat.us:80 fail_timeout=60s max_fails=2;
}
sendfile on;
server {
listen 8080;
server_name dev.lakrids.premier-is.dk;
location / {
proxy_pass http://httpstat.us/;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
答案 2 :(得分:1)
这就是让我的一天(我永远感谢C. Eastwood先生):))
nginx容器在我的设计中兼作反向代理 - 并处理443安全端 - 允许“普通”应用服务器处理业务逻辑:
# ./docker-compose.yml
version: '2'
services:
proxy:
build: ./shared/proxy
networks:
- sand
links:
- devlakrids:devlakrids
ports:
- 80:80
- 443:443
# sand[kassen]
#
devlakrids:
build: ./sand/current/spark
expose:
- "4567"
tmpfs: /tmp
volumes:
- ./sand/current/:/mnt/lakrids
- ./shared/sand/:/shared
links:
- sandmysql
networks:
- sand
- sanddb
# ./shared/proxy/services.conf
server {
listen 80;
listen 443 ssl http2;
server_name dev.lakrids.xxxx.xxx;
# Path for SSL config/key/certificate
ssl on;
ssl_certificate /etc/ssl/certs/nginx/xxx.crt;
ssl_certificate_key /etc/ssl/certs/nginx/xxxx.pem;
include /etc/nginx/includes/ssl.conf;
add_header Strict-Transport-Security "max-age=31536000";
location / {
include /etc/nginx/includes/proxy.conf;
proxy_pass http://devlakrids:4567;
}
access_log off;
error_log /var/log/nginx/error.log error;
}
# ./shared/proxy/includes/proxy.conf
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_request_buffering off;
proxy_http_version 1.1;
proxy_intercept_errors on;
有了这个 - 剩下要做的就是docker-compose up
大体上来了;)