Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Docker 无法使用没有外部IP地址的容器映像创建Google Compute Engine VM_Docker_Google Cloud Platform_Google Compute Engine_Google Container Optimized Os - Fatal编程技术网

Docker 无法使用没有外部IP地址的容器映像创建Google Compute Engine VM

Docker 无法使用没有外部IP地址的容器映像创建Google Compute Engine VM,docker,google-cloud-platform,google-compute-engine,google-container-optimized-os,Docker,Google Cloud Platform,Google Compute Engine,Google Container Optimized Os,我正在尝试使用以下GCLOUD命令使用marketplace POSGRSQL11映像构建VM(尽管对于我尝试过的所有映像,问题似乎都很普遍): gcloud compute instances create-with-container postgres-test \ --container-image gcr.io/cloud-marketplace/google/postgresql11:latest \ --container-env-file=envdata.txt \ -

我正在尝试使用以下GCLOUD命令使用marketplace POSGRSQL11映像构建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数据的外部磁盘

envdata.txt:

POSTGRES_USER=postgresuser
POSTGRES_PASSWORD=postgrespassword
metadata.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上启动

如果我现在通过执行以下命令从云命令的网络接口行中删除no address命令(允许google向VM分配外部IP地址):

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地址?

如果您有公共IP,那么从您的实例到Internet的请求将通过Internet网关。如果您的实例没有公共IP,则需要设置云NAT以提供到Internet的路由。这是最简单的解决办法。如果您只需要访问Google API和服务,而不需要访问公共互联网,请参阅下一个选项

谷歌还提供了
私有谷歌访问
,仅访问谷歌API和服务


嗨,约翰,谢谢你的回复。我似乎遇到的问题是,该实例无法访问作为内部google服务的GCR。问题的原因正是,为什么创建实例不需要访问internet,因为GCR是内部的,那么为什么创建实例似乎依赖于外部访问?GCR服务未连接到您的内部网络(VPC)。它是谷歌网络的一部分。因此,您必须通过我的答案中的一种方法创建连接。