gcloud 常用命令

gsutil

copy bucket to another bucket

1
curl -L https://xx/xxx.rar | gsutil cp - gs://your/folder/xx.rar

update

升级组件

1
gcloud components update

Docker

构建运行docker

  • Dockerfile
1
2
3
4
FROM java:openjdk-8-jdk-alpine
ADD ./root.war /root/root.war
CMD ["java", "-jar", "/root/root.war"]
EXPOSE 8080
  • Depoly
1
2
3
4
5
# 默认美国服务器
gcloud container builds submit --tag gcr.io/[PROJECT_ID]/quickstart-image .

# 选择亚洲服务器
gcloud container builds submit --tag asia.gcr.io/[PROJECT_ID]/quickstart-image .

注意PROJECT_ID不是自定义的,而是自动生成的

官方参考文档

Push Docker

  1. 命令格式:docker tag [IMAGE] [HOSTNAME]/[PROJECT-ID]/[IMAGE]

例如,docker tag quickstart-image gcr.io/my-project/quickstart-image

  1. 命令格式:gcloud docker – push [HOSTNAME]/[PROJECT-ID]/[IMAGE]

例如,gcloud docker – push gcr.io/my-project/quickstart-image

  1. 查看Image

https://console.cloud.google.com/gcr

Pull Docker

  • 命令格式:gcloud docker – pull [HOSTNAME]/[PROJECT-ID]/[IMAGE]

View Docker

  • 命令格式:gcloud container images list [HOSTNAME]/[PROJECT-ID]/[IMAGE]

Delete Docker

  • 命令格式:gcloud container images delete [HOSTNAME]/[PROJECT-ID]/[IMAGE]

转换成Google构建脚本

1
2
3
4
5
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/quickstart-image', '.' ]
images:
- 'gcr.io/$PROJECT_ID/quickstart-image'

构建命令

1
gcloud container builds submit --config cloudbuild.yaml .

注意:在使用上述命令打包本地文件到GCP时候,会检查本地ignore配置文件,对于忽略的文件及文件夹不会被打包到GCP进行构建