[英]Boot2Docker to Google Compute Engine VM: saving Docker container
[英]Cannot create a Google Compute Engine VM with a container image without en external IP address
我正在嘗試使用以下 GCLOUD 命令使用市場 posgresql11 映像構建 VM(盡管對於我嘗試過的所有映像,該問題似乎都很普遍):
gcloud compute instances create-with-container postgres-test \
--container-image gcr.io/cloud-marketplace/google/postgresql11:latest \
--container-env-file=envdata.txt \
--container-mount-host-path mount-path=/var/lib/postgresql,host-path=/mnt/disks/postgres_data,mode=rw \
--machine-type=e2-small \
--scopes=cloud-platform \
--boot-disk-size=10GB \
--boot-disk-device-name=postgres-test \
--create-disk="mode=rw,size=10GB,type=pd-standard,name=postgres-test-data,device-name=postgres-test_data" \
--network-interface=subnet="default,no-address" \
--tags=database-postgres \
--metadata-from-file user-data=metadata.txt
envdata.txt 文件包含映像的環境變量數據, metadata.txt 文件包含 bootcmd 指令,用於格式化和掛載 postgres 數據的外部磁盤。
環境數據.txt:
POSTGRES_USER=postgresuser
POSTGRES_PASSWORD=postgrespassword
元數據.txt:
#cloud-config
bootcmd:
- fsck.ext4 -tvy /dev/sdb
- mkdir -p /mnt/disks/postgres_data
- mount -t ext4 -O ... /dev/sdb /mnt/disks/postgres_data
VM 已創建,但 sudo journalctl 命令顯示嘗試開始連接到 GCR,但這似乎不成功。 用於 postgres 的 docker 映像未下載且未在 VM 上啟動。
如果我現在通過執行以下命令從 cloud 命令的 network-interface 行中刪除 no-address 命令(允許 google 將外部 IP 地址分配給 VM):
gcloud compute instances create-with-container postgres-test \
--container-image gcr.io/cloud-marketplace/google/postgresql11:latest \
--container-env-file=envdata.txt \
--container-mount-host-path mount-path=/var/lib/postgresql,host-path=/mnt/disks/postgres_data,mode=rw \
--machine-type=e2-small \
--scopes=cloud-platform \
--boot-disk-size=10GB \
--boot-disk-device-name=postgres-test \
--create-disk="mode=rw,size=10GB,type=pd-standard,name=postgres-test-data,device-name=postgres-test_data" \
--network-interface=subnet="default" \
--tags=database-postgres \
--metadata-from-file user-data=metadata.txt
然后創建一個 VM,下載並執行 POSTGRES 映像。 sudo journalctl 顯示與 GCR 的連接正在啟動並已啟動。
誰能向我解釋為什么在我的情況下執行圖像取決於具有外部 IP 以及如何使用 GCR 創建 VM 而無需為實例分配外部 IP 地址?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.