Mount S3 Bucket to a Local System

In this exercise, we will try to mount s3 to local system with s3fs package.

Mount the s3 bucket to local directory

aws configure

aws s3 mb s3://testbucket

sudo cp -r ~/.aws /root
# install s3fs
sudo yum install s3fs-fuse -y

mkdir /mnt/s3data
sudo s3fs {BUCKET_name} /mnt/s3data -o allow_other -o default_acl=public-read -o use_cache=/tmp/s3fs

echo "<html><h1>test</h1><html>" > index.html

#check file in local folder and s3
ll /mnt/s3data
aws s3 ls s3://{BUCKET_name}

Access the s3 bucket data from Docker Container

Once mounted we can access the data in a container as well

docker run -d --name web1 -p 80:80 --mount type=bind,source=/mnt/s3data,target=/usr/local/apache2/htdocs,readonly httpd:2.4