[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
相关文章
- Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
- aws linux no python application found, check your startup logs for errors
- Docker查看容器命令(docker ps)
- 「 【Docker】用docker运行2048小游戏(玩转docker) 」
- 首次揭秘AWS网络长成史:工程是取舍的艺术
- 【Docker 系列】docker 学习 一,Docker的安装使用及Docker的基本工作原理
- 【Docker 系列】docker 学习六,DockerFile
- 如何使用awsEnum基于提供的凭证枚举AWS云端资源
- LambdaGuard:一款针对AWS无服务器环境安全的审计工具
- Linux使用root用户登录(AWS EC2)
- AWS回应Elastic修改开源协议:创建“真正”开源的Elasticsearch分支
- MySQL Error number: MY-011421; Symbol: ER_KEYRING_AWS_INVALID_DATA_FILE_PATH; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-011440; Symbol: ER_KEYRING_AWS_FAILED_TO_RE_ENCRYPT_KEY; SQLSTATE: HY000 报错 故障修复 远程处理
- Docker容器的重启策略及docker run的–restart选项详解程序员
- 亚马逊AWS S3故障4小时,波及 Adobe、Slack 等数千家线上服务
- 数据库使用AWS连接本地MySQL数据库(aws调用本地mysql)
- AWS快速拉取MySQL日志,轻松管理日志记录(aws拉取mysql日志)
- 灵活的云计算利用AWS S3和MySQL让你的业务更上一层楼(awss3mysql)
- 云端AWS和企业级数据库 Oracle的尝试之路(aws oracle)
- 探索Docker安装Oracle数据库的秘密(docker安装oracle)
- 的docker容器创建并使用Docker容器启动Redis数据库(创建并启动名为redis)
- JEDI后,AWS与微软Azure“再战”100亿美元云计算大单