所以这就是我要做的事情:
Nginx容器链接到 - >运行Puma的Rails容器
使用docker-compose,这个解决方案很有效。我可以启动两个容器,NGINX容器可以访问链接容器中端口3000上运行的服务。不幸的是,在将其转移到AWS ECS时,我一直在努力解决这些问题。
首先,Dockerfile for Rails的相关位:
ENV RAILS_ROOT /www/apps/myapp
RUN mkdir -p $RAILS_ROOT
WORKDIR $RAILS_ROOT
.... lots of files get put in their proper places ....
EXPOSE 3000
VOLUME [/www/apps/myapp/]
CMD puma -C config/puma.rb'
我确认puma正按预期启动,并且似乎在端口3000上提供tcp流量。
我的nginx配置的相关部分:
upstream puma {
fail_timeout=0;
server myapp:3000;
}
server {
listen 80 default deferred;
server_name *.myapp.com;
location ~ (\.php$|\.aspx$|wp-admin|myadmin) {
return 403;
}
root /www/apps/myapp/public;
try_files $uri/index.html $uri @puma;
Nginx dockerfile:
ENV RAILS_ROOT /www/apps/myapp
# Set our working directory inside the image
WORKDIR $RAILS_ROOT
EXPOSE 80
这是我的ECS任务定义:
{
"family": "myapp",
"containerDefinitions": [
{
"name": "web",
"image": "%REPOSITORY_URI%:nginx-staging",
"cpu": 512,
"memory": 512,
"portMappings": [
{
"containerPort": 80,
"protocol": "tcp"
},
{
"containerPort": 443,
"protocol": "tcp"
}
],
"links": [
"myapp"
],
"volumesFrom": [
{
"sourceContainer": "myapp",
"readOnly": false
}
],
"essential": true,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "awslogs-myapp-staging",
"awslogs-region": "us-west-2",
"awslogs-stream-prefix": "awslogs-myapp-nginx"
}
}
},
{
"image": "%REPOSITORY_URI%:v_%BUILD_NUMBER%",
"name": "myapp",
"cpu": 2048,
"memory": 2056,
"essential": true,
...bunch of environment variables, etc.
}
我可以从我的nginx容器中ping myapp容器,所以我认为这不是安全组问题。
答案 0 :(得分:0)
这结果是AWS安全组问题。我愚蠢地期望Rails应用程序可能提醒我它无法到达数据库,而是它只是永远挂在那里直到我用rails c手动启动它。然后我得到了超时,这导致了快速解决。