DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Driving DevOps With Smart, Scalable Testing
  • Container Checkpointing in Kubernetes With a Custom API
  • A Guide to Automating AWS Infrastructure Deployment
  • A Guide to Microservices Deployment: Elastic Beanstalk vs Manual Setup

Trending

  • After 9 Years, Microsoft Fulfills This Windows Feature Request
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Mastering Deployment Strategies: Navigating the Path to Seamless Software Releases
  • How To Build AI-Powered Prompt Templates Using the Salesforce Prompt Builder
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Mounting an EBS Volume to Docker on AWS Elastic Beanstalk

Mounting an EBS Volume to Docker on AWS Elastic Beanstalk

By 
Jakub Holý user avatar
Jakub Holý
·
Jun. 03, 15 · Interview
Likes (0)
Comment
Save
Tweet
Share
14.5K Views

Join the DZone community and get the full member experience.

Join For Free

Mounting an EBS volume to a Docker instance running on Amazon Elastic Beanstalk (EB) is surprisingly tricky. The good news is that it is possible.

I will describe how to automatically create and mount a new EBS volume (optionally based on a snapshot). If you would prefer to mount a specific, existing EBS volume, you should check out leg100’s docker-ebs-attach (using AWS API to mount the volume) that you can use either in a multi-container setup or just include the relevant parts in your own Dockerfile.

The problem with EBS volumes is that, if I am correct, a volume can only be mounted to a single EC2 instance – and thus doesn’t play well with EB’s autoscaling. That is why EB supports only creating and mounting a fresh volume for each instance.

Why would you want to use an auto-created EBS volume? You can already use a docker VOLUME to mount a directory on the host system’s ephemeral storage to make data persistent across docker restarts/redeploys. The only advantage of EBS is that it survives restarts of the EC2 instance but that is something that, I suppose, happens rarely. I suspect that in most cases EB actually creates a new EC2 instance and then destroys the old one. One possible benefit of an EBS volume is that you can take a snapshot of it and use that to launch future instances. I’m now inclined to believe that a better solution in most cases is to set up automatic backup to and restore from S3, f.ex. using duplicity with its S3 backend (as I do for my NAS).

Anyway, here is how I got EBS volume mounting working. There are 4 parts to the solution:

  1. Configure EB to create an EBS mount for your instances
  2. Add custom EB commands to format and mount the volume upon first use
  3. Restart the Docker daemon after the volume is mounted so that it will see it (see this discussion)
  4. Configure Docker to mount the (mounted) volume inside the container

1-3.: .ebextensions/01-ebs.config:

# .ebextensions/01-ebs.config
commands:
  01format-volume:
    command: mkfs -t ext3 /dev/sdh
    test: file -sL /dev/sdh | grep -v 'ext3 filesystem'
    # ^ prints '/dev/sdh: data' if not formatted
  02attach-volume:
    ### Note: The volume may be renamed by the Kernel, e.g. sdh -> xvdh but
    #       /dev/ will then contain a symlink from the old to the new name
    command: |
      mkdir /media/ebs_volume
      mount /dev/sdh /media/ebs_volume
      service docker restart # We must restart Docker daemon or it wont' see the new mount
    test: sh -c "! grep -qs '/media/ebs_volume' /proc/mounts"
option_settings:
   # Tell EB to create a 100GB volume and mount it to /dev/sdh
   - namespace: aws:autoscaling:launchconfiguration
     option_name: BlockDeviceMappings
     value: /dev/sdh=:100

4.: Dockerrun.aws.json and Dockerfile:

Dockerrun.aws.json: mount the host’s /media/ebs_volume as /var/easydeploy/share inside the container:

{
  "AWSEBDockerrunVersion": "1",
  "Volumes": [
    {
      "HostDirectory": "/media/ebs_volume",
      "ContainerDirectory": "/var/easydeploy/share"
    }
  ]
}

Dockerfile: Tell Docker to use a directory on the host system as /var/easydeploy/share – either a randomly generated one or the one given via the -m mount option to docker run:

...
VOLUME ["/var/easydeploy/share"]
...
AWS Docker (software) AWS Elastic Beanstalk

Published at DZone with permission of Jakub Holý, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Driving DevOps With Smart, Scalable Testing
  • Container Checkpointing in Kubernetes With a Custom API
  • A Guide to Automating AWS Infrastructure Deployment
  • A Guide to Microservices Deployment: Elastic Beanstalk vs Manual Setup

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!