首页 > 其他分享 >[Docker] Storing Container Data in AWS S3

[Docker] Storing Container Data in AWS S3

时间:2023-01-28 17:44:06浏览次数:41  
标签:Storing widget Container S3 mnt bucket factory Docker

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

  1. Install the awscli, while checking if there are any versions currently installed, and not stopping any user processes: pip install --upgrade --user awscli
  2. Configure the CLI: aws configure
  3. 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
  4. Copy the CLI configuration to the root user: sudo cp -r ~/.aws /root
  5. Install the s3fs package: sudo yum install s3fs-fuse -y

Prepare the Bucket

  1. Create a mount point for the s3 bucket: sudo mkdir /mnt/widget-factory
  2. Export the bucket name: export BUCKET=<S3_BUCKET_NAME>
  3. Mount the S3 bucket: sudo s3fs $BUCKET /mnt/widget-factory -o allow_other -o default_acl=public-read -o use_cache=/tmp/s3fs
  4. Verify that the bucket was mounted successfully: ll /mnt/widget-factory
  5. Copy the website files to the s3 bucket: cp -r ~/widget-factory-inc/web/* /mnt/widget-factory
  6. Verify the files are in the folder: ll /mnt/widget-factory
  7. Verify the files are in the s3 bucket: aws s3 ls s3://$BUCKET

Use the S3 Bucket Files in a Docker Container

  1. 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
  2. In a web browser, verify connectivity to the container: <SERVER_PUBLIC_IP_ADDRESS>
  3. Check the bucket cache:  
  4. Change to the /mnt/widget-factory/ directory: cd /mnt/widget-factory
  5. Create a new page within the bucket: cp index.html newPage.html
  6. In a web browser, verify that the new page is accessible: <SERVER_PUBLIC_IP_ADDRESS>/newPage.html
  7. Verify that the page was added to the bucket: aws s3 ls $BUCKET

标签:Storing,widget,Container,S3,mnt,bucket,factory,Docker
From: https://www.cnblogs.com/Answer1215/p/17070977.html

相关文章

  • upload-labs pass3,phpstudy中修改httpd.conf后无法解析.php3后缀。phpstudy中64与32系
    问题解决参考自:https://www.likecs.com/show-965809.html 注意:VC运行库(V14-x64)版本必须与Apache、PHP版本相同;VC就是MicrosoftVisualC++,可以通过控制面板查看否则......
  • [Docker] Storing Container Data in Google Cloud Storage
    IntroductionDockervolumesisthepreferredmethodofstoringcontainerdatalocally.VolumesupportisbuiltdirectlyintoDocker,makingitaneasytoolto......
  • [Docker] Storing Container Data In Docker Volumes
    Storingdatawithinacontainerimageisoneoptionforautomatingacontainerwithdata,butitrequiresacopyofthedatatobeineachcontaineryourun.F......
  • [Docker] Handcrafting a Container Image
    Pullhttpdimageandrunthecontainer[cloud_user@ip-10-0-1-78~]$dockerpullhttpd:2.4[cloud_user@ip-10-0-1-78~]$dockerrun--namewebtemplate-dhttpd:2......
  • s3c2440 gcc交叉编译工具链制作
    前言:因为准备学习lwip,之前在stm32上移植跟着教程走得差不多了,但是用的keil。所以想在一个新平台移植一下巩固巩固,正好有2440的板子,也学一下gcc-make这样的开发流程,配套的......
  • Java CSS3
    CSS层叠级联样式表快速入门CSS可以在html文件中写,写在<style>中,一般style写在head中(HTML,CSS没有分离)<style>h1(选择器){ 可以设置h1的属性(声明,分号结尾)}<......
  • java CSS3
    CSS层叠级联样式表快速入门CSS可以在html文件中写,写在<style>中,一般style写在head中(HTML,CSS没有分离)<style> h1(选择器){可以设置h1的属性(声明,分号结尾)......
  • mkdocs3
    title:解决mkdocs部署GithubPages自定义域名失效的问题tags:-Mkdocs在/docs目录下创建一个CNAME的无后缀文件,然后在里面填入你的域名因为每次在Custom......
  • CSS3学习笔记
    CSS3学习笔记            CSS3选择器总结(表格)html标签有2种关系:包含关系和并列关系;CSS3选择器分类:基本选择器、组合选择器、属性选择器、伪类......
  • CSS3选择器总结(表格)
    CSS3选择器总结(表格)html标签有2种关系:包含关系和并列关系;CSS3选择器分类:基本选择器、组合选择器、属性选择器、伪类选择器;伪类选择器分类:动态伪类、结构伪类、状态伪类......