Storing Container Data in AWS S3

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Using Docker volumes is the preferred method of storing container data locally. Volume support is built directly into Docker, making it an easy tool to use for storage, as well as more portable. However, storing container data in Docker volumes still requires you to back up the data in those volumes on your own. There is another option – storing your container data in the cloud. It’s not a solution for every problem, but after this lab, you’ll have another tool at your disposal. This lab will show you how to mount an S3 bucket onto your local system as a directory. You will then mount that directory into your Docker container. We will use an httpd container to serve the contents of that bucket as a webpage, but you can use it to share any common data between containers. This will demonstrate how flexible Docker can be. You can make changes to your bucket and all of your containers using the S3 bucket will near-instantly have access to the content.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Configuration and Installation
  1. Install the AWS CLI.
  2. Configure the AWS CLI for your user.
    • Use the Access Key ID and Secret Access Key provided in your lab credentials.
    • Use us-east-1 as the default region.
    • Output is optional, but json is a good choice.
  3. Copy the credentials to the root user.
  4. Install s3fs-fuse. This package is in EPEL, which is already installed on the server.
Prepare the Bucket
  1. Create a mount point on the server.
  2. Mount the S3 bucket.
    • Use the bucket name provided to you with the lab credentials. It is helpful to set this as an environment variable.
    • To prevent a lot of extra calls to S3 that will increase your AWS bill, enable local file system caching by setting the use_cache option when mounting.
  3. Copy the website files into the bucket.
  4. Verify the files are in the folder.
  5. Verify the files are in the S3 bucket.
Use the S3 Bucket Files in a Docker Container
  1. Run an httpd container to serve the website. Remember to mount the bucket and publish the web server port.
  2. View the webpage in a browser. Use the server’s public IP provided with the lab.
  3. Create a new page in the bucket, called newPage.html, by making a copy of an existing page.
  4. View the new webpage in a browser. This will be at: http://<ServerPublicIP>/newPage.html.
  5. Verify that the new webpage is in the S3 bucket.

Additional Resources

Scenario

While working on upgrading your website to a Docker container, you should explore other options for storing container data. One alternative to storing static content in a Docker volume, is to store the data in an AWS S3 bucket.

If you are already using AWS, this would allow you to not worry about backing up container data, thanks to the data being stored in the S3 bucket.

You will be using s3fs, a FUSE-based file system, to mount the S3 bucket to your server. You'll prepare the server by installing all necessary tools. You'll then copy the website data, cloned from GitHub into cloud_user's home directory, to the S3 bucket. You'll use a bind mount to get your S3 bucket directory into your container; and finally, you'll view the content from a web browser.

Note: While this method works for static content, or content that changes occasionally, this should not be used for files that are written frequently, such as a database. That will drastically increase latency and drive up your cloud storage costs. We enable local caching and mount the data as read-only in the container to help mitigate these issues. You can, however, use this method for data output if the container processes a job that emits uniquely-named output.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?