I am posting about docker a lot recently because these blog post been in my Drafts for long time waiting someone to finish them 😅 and Finally I had chance to do that.
I posted recently about storing container data in AWS s3 , but this time the same topic but for Google Cloud and how to configure that.
Configuration
- Export some Linux variables to save time.
export projnum=$(curl http://metadata.google.internal/computeMetadata/v1/project/numeric-project-id -sH "Metadata-Flavor: Google")
export BUCKET="Osama-${projnum}"
- Verify that the variable was set successfully
echo $projnum
echo $BUCKET
- Prepare the cloud storage, using gsutil, create a new bucket
gsutil mb -l us-central1 -c standard gs://$BUCKET
- Install gcsfuse
sudo yum install -y gcsfuse
- Update the fuse.conf file to allow the user to mount the bucket properly
sudo sed -ri 's/# user_allow_other/user_allow_other/' /etc/fuse.conf
- Configure the directories needed to mount the bucket
sudo mkdir /mnt/Osama /tmp/gcs
- Change ownership of the directories to the Current user if you choose to skip this step then you will not have access
sudo chown Osama: /mnt/Osama/ /tmp/gcs
- Mount the bucket
gcsfuse -o allow_other --temp-dir=/tmp/gcs $BUCKET /mnt/Osama/
- Copy the website files into the bucket by copy Command
- List the contents of the bucket
gsutil ls gs://$BUCKET
Use Bucket inside the container
- Mount the directory into the Docker container
docker run -d --name web1 --mount type=bind,source=/mnt/Osama,target=/usr/local/apache2/htdocs,readonly -p 80:80 httpd:2.4
Enjoy
Simple and Fun 😉
Osama