gpt4 book ai didi

google-cloud-platform - 谷歌云启动脚本未运行

转载 作者:行者123 更新时间:2023-12-01 11:17:15 25 4
gpt4 key购买 nike

启动脚本的行为方式与我预期的不同。

我在存储桶中有一个 .sh 文件,并包含一个 startup-script-url 元标记,其值为 gs://bucket-名称/start-script.sh

[[0;32m  OK  [0m] Started Google Compute Engine Accounts Daemon.
Starting Google Compute Engine Startup Scripts...
[[0;32m OK [0m] Started Google Compute Engine Shutdown Scripts.
[[0;32m OK [0m] Started Google Compute Engine Startup Scripts.
[[0;32m OK [0m] Started Docker Application Container Engine.
[[0;32m OK [0m] Started Wait for Google Container Registry (GCR) to be accessible.
[[0;32m OK [0m] Reached target Google Container Registry (GCR) is Online.
[[0;32m OK [0m] Started Containers on GCE Setup.
[ 8.001248] konlet-startup[1018]: 2018/03/08 20:23:56 Starting Konlet container startup agent

以下脚本未按预期执行。我尝试使用 startup-script 元数据标记并使用像 echo "hello" 这样简单的东西,但这也不起作用。我启用了完整的 Cloud API 访问范围。

如果我复制以下文件的内容并将其粘贴到 ssh 终端,它就可以完美运行。

真的需要一些帮助=D

启动脚本.sh

#! /bin/bash

image_name=gcr.io/some-image:version-2
docker_images=$(docker inspect --type=image $image_name)
array_count=${#docker_images[0]}

# Check if docker image is available
while ((array_count = 2));
do
docker_images=$(docker inspect --type=image ${image_name})
array_count=${#docker_images[0]}

if (($array_count > 2)); then
break
fi
done

################################
#
# Docker image now injected
# by google compute engine
#
################################

echo "docker image ${image_name} available"

container_ids=($(docker container ls | grep ${image_name} | awk '{ print $1}'))

for (( i=0; i < ${#container_ids[@]}; i++ ));
do
# run command for each container
container_id=${container_ids[i]}
echo "running commands for container: ${container_ids[i]}"

# start cloud sql proxy
docker container run -d -p $HOST_PORT:$APPLICATION_PORT \
${container_ids[i]} \
./cloud_sql_proxy \
-instances=$PG_INSTANCE_CONNECTION_NAME=tcp:$PG_PORT \
-credential_file=$PG_CREDENTIAL_FILE_LOCATION

# HTTP - Start unicorn webserver
docker exec -d \
${container_ids[i]} \
bundle exec unicorn -c config/unicorn.rb
done

最佳答案

好的...经过一些场景测试...发现如果您使用“将容器镜像部署到此 VM 实例”选项,启动脚本不会运行。希望这可以帮助您避免撕掉你的头发哈哈。

Deploy a container image to this VM instance Option

关于google-cloud-platform - 谷歌云启动脚本未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49182118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com