[Docker] Storing Container Data in Google Cloud Storage
Introduction
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 a Cloud Storage 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 hands-on lab will demonstrate how flexible Docker can be. You can make changes to your bucket and all of your containers using the Cloud Storage 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>
Note: You may continue as
cloud_user
for the duration of the lab. You do not need to elevate to root user privileges to follow this lab guide.
Configuration and Installation
- Export the
projnum
variable:export projnum=$(curl http://metadata.google.internal/computeMetadata/v1/project/numeric-project-id -sH "Metadata-Flavor: Google")
- Verify that the variable was set successfully:
echo $projnum
- Export the
BUCKET
variable:export BUCKET="widgetfactory-${projnum}"
Prepare the Cloud Storage Bucket
- Using
gsutil
, create a new bucket:gsutil mb -l us-central1 -c standard gs://$BUCKET
- Verify that the
gcsfuse
repo is available on the server:cat /etc/yum.repos.d/gcsfuse.repo
- Install
gcsfuse
(Note: please wait a few minutes before continuing to allow the lab's startup scripts to release the yum lock).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/widget-factory /tmp/gcs
- Change ownership of the directories to the
cloud_user
:sudo chown cloud_user: /mnt/widget-factory/ /tmp/gcs
- Mount the bucket:
gcsfuse -o allow_other --temp-dir=/tmp/gcs $BUCKET /mnt/widget-factory/
- Copy the website files into the bucket:
cp -r /home/cloud_user/widget-factory-inc/web/* /mnt/widget-factory/
- List the contents of the bucket:
gsutil ls gs://$BUCKET
Use the GCS Bucket in a Container
- Mount the directory into the Docker container:
sudo docker run -d --name web1 --mount type=bind,source=/mnt/widget-factory,target=/usr/local/apache2/htdocs,readonly -p 80:80 httpd:2.4
- Using a web browser, verify connectivity to the container:
<SERVER_PUBLIC_IP_ADDRESS>
相关文章
- [Google Guava] 3-缓存
- Docker 系列(十):docker服务发现
- Unity3D研究院之脚本生成Android Google Project
- 【Docker】docker安装Jenkins
- 【Docker】docker安装GitLab
- 【Docker】iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8480 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name
- Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
- 基于Google Reader发展起来的个性化推荐系统之三大问题
- centos ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
- Google Chrome v48.0.2564.
- WebP官方翻译==Google推出新的图片格式WebP
- 使用google chart api生成报表图片
- 【收藏】在QGIS中导入GOOGLE、BING等地图和卫星影像(插件方式和XYZ方式)
- Multiple dex files define Lcom/google/zxing/BarcodeFormat
- Google protocol buff使用
- 83.第十七章 企业级容器技术docker -- Docker Compose、Docker 仓库管理(十一)
- 怎样訪问Google
- 有效单词词广场——算法面试刷题5(for google),考察数学
- 【云原生 • Docker】docker 私有仓库的搭建、配置与镜像上传
- Docker学习笔记17:docker实例之安装 Node.js、PHP、MySQL、Tomcat、Python、Redis、MongoDB、Apache
- Docker学习笔记07:docker使用之容器使用
- 【Docker系列】2.Linux 安装docker+docker-compose
- 云原生之部署Docker可视化管理工具docker.ui
- Google图片url搜索测试