4

AWS Beanstalk can run applications from Docker containers. As mentioned in the docs (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_image.html) it's possible to write directory mappings to the EC2 volume in the Dockerrun.aws.json:

"Volumes": [
{
  "HostDirectory": "/var/app/mydb",
  "ContainerDirectory": "/etc/mysql"
}

but, is it possible to mount specific EBS volume?

F.e. I need to run db in the Docker container and deploy it with Beanstalk. It's clear that I need to have persistence of the data, backup/restore for db, etc..

Dmitry Ziolkovskiy
  • 3,834
  • 2
  • 18
  • 20

2 Answers2

5

You can mount EBS volumes on any Beanstalk environment. This volume will be available on the EC2 instances.

You can do this using ebextensions option settings. Create a file in your app source .ebextensions/01-ebs.config with the following contents:

option_settings:
   - namespace: aws:autoscaling:launchconfiguration
     option_name: BlockDeviceMappings
     value: /dev/sdj=:100,/dev/sdh=snap-51eef269,/dev/sdb=ephemeral0

The format of the mapping is device name=volume where the device mappings are specified as a single string with mappings separated by a comma. This example attaches to all instances in the autoscaling group an empty 100-GB Amazon EBS volume, an Amazon EBS volume with the snapshot ID snap-51eef269, and an instance store volume.

Read more details about this option setting here. Read more about ebextensions here.

Once you have mounted the EBS volume for your beanstalk environment instances, you can use the volume mapping as above to map directories per your need.

Rohit Banga
  • 18,458
  • 31
  • 113
  • 191
  • does it work with Docker too? Where to place this file in that case? – Dmitry Ziolkovskiy Aug 05 '14 at 09:25
  • The file should be kepf in the root directory. It will work with Docker and the EBS volume will be attached to the EC2 instance. You still have to map it inside your container. – Rohit Banga Aug 05 '14 at 14:37
  • In my experience it does not work with Docker if I mount it as described here: https://blogs.aws.amazon.com/application-management/post/Tx224DU59IG3OR9/Customize-Ephemeral-and-EBS-Volumes-in-Elastic-Beanstalk-Environments because the Docker volume is mounted before the EBS volume (and thus Docker sees the /host/mountpoint/ empty dir as it was before EBS was mounted to it). But perhaps I just screwed up something ... – Jakub Holý May 27 '15 at 11:40
  • BTW This cannot mount a _specific volume_ - it creates a new volume or, at best, a new volume based on an existing snapshot (which makes sense since EB is meant for auto-scaling but you cannot attach to same EBS volume to multiple instances [I believe]). But you could still use .ebextensions and the AWS API to mount the specific volume manually (if your EB app ever only has a single instance) – Jakub Holý May 27 '15 at 11:43
1

I guess the leg100/docker-ebs-attach Docker container does what you want, i.e. make a particular existing EBS volume available. You can either copy the .py file and relevant Dockerfile statements or create a multi-container EB setup and mount the volume from this container.

BTW I have tried to mount a new EBS volume as proposed by Rohit (+ commands to format and mount it) and it works but Docker does not see the mount until the docker daemon is restarted.

Jakub Holý
  • 6,019
  • 3
  • 33
  • 33