所以,这就是我要做的事情:
Nginx容器链接到 - >运行Puma的Rails容器
使用docker-compose,这个解决方案很有效。我能够启动两个容器,NGINX容器可以使用volumes_from访问链接容器中的卷。
首先,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
Nginx配置非常基础,相关部分在这里:
ENV RAILS_ROOT /www/apps/myapp
# Set our working directory inside the image
WORKDIR $RAILS_ROOT
EXPOSE 80
EXPOSE 443
同样,这在docker-compose中都很有效。但是,在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.
}
任务在预期的ECS中开始,myapp容器看起来很完美。但是,当我使用
检出EC2实例主机上的nginx容器时docker exec -it <container> bash
我登陆/ www / apps / myapp,但目录为空。我试图安装驱动器并做其他一些事情,我在这里不知所措......任何人都有任何关于如何从链接容器中获取文件以便在我的nginx容器中使用的想法?
答案 0 :(得分:0)
当然,在我发布之后,我找到了解决方案。所以没有人能够感受到这种痛苦,这就是:
VOLUME [/www/apps/myapp/]
VOLUME ["/www/apps/myapp/"]
叹息