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.
Successfully complete this lab by achieving the following learning objectives:
- Configuration and Installation
- Install the AWS CLI.
- Configure the AWS CLI for your user.
- Use the Access Key ID and Secret Access Key provided in your lab credentials.
us-east-1as the default region.
- Output is optional, but
jsonis a good choice.
- Copy the credentials to the
s3fs-fuse. This package is in EPEL, which is already installed on the server.
- Prepare the Bucket
- Create a mount point on the server.
- 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_cacheoption when mounting.
- Copy the website files into the bucket.
- Verify the files are in the folder.
- Verify the files are in the S3 bucket.
- Use the S3 Bucket Files in a Docker Container
- Run an
httpdcontainer to serve the website. Remember to mount the bucket and publish the web server port.
- View the webpage in a browser. Use the server’s public IP provided with the lab.
- Create a new page in the bucket, called
newPage.html, by making a copy of an existing page.
- View the new webpage in a browser. This will be at:
- Verify that the new webpage is in the S3 bucket.
- Run an