Data Containers in Elastic Beanstalk

Elastic-Beanstalk_clr_144ptIn deploying a multicontainer Docker application to Elastic Beanstalk I needed to mount a volume from one container into another. Something similar to:

docker run --volumes-from my-data-container my-container

I got a little stuck because the docs for running a multicontainer application in Beanstalk talk about mounting volumes on the host but not between containers. The solution is to look at the documentation for ECS itself. Which makes sense since that’s what Beanstalk is using under the covers.

One note on the ECS documentation is that you do not need a “volumes” section nor do you need to define the exported volumes in your data container. Doing so will wipe out the data in your data volume. Simply the following is enough:

"containerDefinitions": [
    {
      "name": "app-container",
      "image": "my-app:latest",
      "essential": true,
      "memory": 128,
      "volumesFrom": [
        {
          "sourceContainer" : "my-app-data"
        }
      ],
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ]
    },
    {
      "name": "my-app-data",
      "image": "my-app-data:latest",
      "essential": false,
      "memory": 128
    }
]

Hope this helps!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s