[Docker] Storing Container Data in AWS S3
Storing Container Data in AWS S3
Introduction
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.
Solution
Log in to the server using the credentials provided:
ssh cloud_user@<PUBLIC_IP_ADDRESS>
Configuration and Installation
- Install the
awscli
, while checking if there are any versions currently installed, and not stopping any user processes:pip install --upgrade --user awscli
- Configure the CLI:
aws configure
- Enter the following:
- AWS Access Key ID: <ACCESS_KEY_ID>
- AWS Secret Access Key: <SECRET_ACCESS_KEY>
- Default region name: us-east-1
- Default output format: json
- Copy the CLI configuration to the
root
user:sudo cp -r ~/.aws /root
- Install the
s3fs
package:sudo yum install s3fs-fuse -y
Prepare the Bucket
- Create a mount point for the s3 bucket:
sudo mkdir /mnt/widget-factory
- Export the bucket name:
export BUCKET=<S3_BUCKET_NAME>
- Mount the S3 bucket:
sudo s3fs $BUCKET /mnt/widget-factory -o allow_other -o default_acl=public-read -o use_cache=/tmp/s3fs
- Verify that the bucket was mounted successfully:
ll /mnt/widget-factory
- Copy the website files to the s3 bucket:
cp -r ~/widget-factory-inc/web/* /mnt/widget-factory
- Verify the files are in the folder:
ll /mnt/widget-factory
- Verify the files are in the s3 bucket:
aws s3 ls s3://$BUCKET
Use the S3 Bucket Files in a Docker Container
- Run an
httpd
container using the S3 bucket:docker run -d --name web1 -p 80:80 --mount type=bind,source=/mnt/widget-factory,target=/usr/local/apache2/htdocs,readonly httpd:2.4
- In a web browser, verify connectivity to the container:
<SERVER_PUBLIC_IP_ADDRESS>
- Check the bucket cache:
- Change to the
/mnt/widget-factory/
directory:cd /mnt/widget-factory
- Create a new page within the bucket:
cp index.html newPage.html
- In a web browser, verify that the new page is accessible:
<SERVER_PUBLIC_IP_ADDRESS>/newPage.html
- Verify that the page was added to the bucket:
aws s3 ls $BUCKET
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2019-01-28 [Angular] Angular Custom Change Detection with ChangeDetectorRef
2019-01-28 [Parcel] Running TypeScript with parcel-bundler
2018-01-28 [MST] Defining Asynchronous Processes Using Flow
2018-01-28 [MST] Restore the Model Tree State using Hot Module Reloading when Model Definitions Change
2018-01-28 [MST] Store Store in Local Storage
2018-01-28 [MST] Create an Entry Form to Add Models to the State Tree
2018-01-28 [MST] Remove Model Instances from the Tree