Search code examples
ruby-on-railsdockernginxamazon-ecs

Mounted volume using volume-from is empty


So here's what I'm trying to do:

Nginx container linked to -> Rails container running Puma

Using docker-compose, this solution works great. I'm able to start both containers and the NGINX container has access to the volume in the linked container using volumes_from.

First, the relevant bits of the 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 config is pretty basic, relevant parts are here:

ENV RAILS_ROOT /www/apps/myapp

# Set our working directory inside the image
WORKDIR $RAILS_ROOT

EXPOSE 80
EXPOSE 443

Again, this all works great in docker-compose. However, in ECS, I'm trying to use the following task definition:

{
"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.
}

The task starts in ECS as expected, and the myapp container looks perfect. However, when I check out the nginx container on the EC2 instance host with

docker exec -it <container> bash

I land in /www/apps/myapp, but the directory is empty. I've tried to mount drives and do several other things and I'm at a loss here... anyone have any ideas as to how to get the files from the linked container to be usable in my nginx container?


Solution

  • And of course, right after I post this I find the solution. So no one else has to feel this pain, here it is:

    VOLUME [/www/apps/myapp/]
    
    VOLUME ["/www/apps/myapp/"]
    

    sigh