如何使用谷歌云计算引擎启动脚本自动克隆Docker容器内的git仓库。 只能交互使用

我开始这样一个谷歌云计算引擎:

gcloud compute instances create cloudml \ --image-family=container-vm \ --image-project=google-containers \ --machine-type=n1-highmem-8 \ --metadata-from-file startup-script=Job.sh 

我的启动脚本的顶部看起来像

 #!/bin/bash #get git keys gsutil cp -r gs://[mybucket]/.ssh/id_rsa ~/.ssh/ gsutil cp -r gs://[mybucket]/.ssh/id_rsa.pub ~/.ssh/ chmod 400 ~/.ssh/id_rsa #run docker container and pass keys sudo docker run -it -v /home/ben/.ssh/:/root/.ssh/ gcr.io/api-project-773889352370/rwhales bin/bash #add git to known hosts. ssh-keyscan github.com >> ~/.ssh/known_hosts #clone repo git clone git@github.com:bw4sz/WhalePhys.git --depth 1 cd WhalePhys #make new branch git checkout -b $(hostname) #render script Rscript -e "rmarkdown::render('RunModel.Rmd')" &> run.txt 

这里的目标是克隆一个repo并在docker容器中执行一个文件。 交互式地,这个工作没有问题。

但是,当我从启动脚本运行这里发生了什么。

它拉动docker的图像

 Dec 23 20:55:51 cloudml startupscript: latest: Pulling from api-project-773889352370/rwhales Dec 23 20:55:51 cloudml startupscript: 3e17c6eae66c: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: fce7c67b7824: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: 6f91e98067d1: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: 8378bed4dab2: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: b2f901dfbe7f: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: bdcb07accb69: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: 9e9d56f1f99b: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: 0454c6c3871b: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: 2d8e1f2e409d: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: 227225d89949: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: 25ed206e474f: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: 6649046050df: Pulling fs layer Dec 23 20:55:51 cloudml startupscript: bdcb07accb69: Waiting Dec 23 20:55:51 cloudml startupscript: 227225d89949: Waiting Dec 23 20:55:51 cloudml startupscript: 2d8e1f2e409d: Waiting Dec 23 20:55:51 cloudml startupscript: 25ed206e474f: Waiting Dec 23 20:55:51 cloudml startupscript: b2f901dfbe7f: Waiting Dec 23 20:55:51 cloudml startupscript: 9e9d56f1f99b: Waiting Dec 23 20:55:51 cloudml startupscript: 0454c6c3871b: Waiting Dec 23 20:55:51 cloudml startupscript: 6649046050df: Waiting Dec 23 20:55:53 cloudml startupscript: 3e17c6eae66c: Download complete Dec 23 20:55:53 cloudml startupscript: 8378bed4dab2: Verifying Checksum Dec 23 20:55:53 cloudml startupscript: 8378bed4dab2: Download complete Dec 23 20:55:53 cloudml startupscript: b2f901dfbe7f: Verifying Checksum Dec 23 20:55:53 cloudml startupscript: b2f901dfbe7f: Download complete Dec 23 20:55:54 cloudml startupscript: 6f91e98067d1: Verifying Checksum Dec 23 20:55:54 cloudml startupscript: 6f91e98067d1: Download complete Dec 23 20:55:56 cloudml startupscript: fce7c67b7824: Verifying Checksum Dec 23 20:55:56 cloudml startupscript: fce7c67b7824: Download complete Dec 23 20:55:56 cloudml startupscript: 3e17c6eae66c: Pull complete Dec 23 20:56:01 cloudml startupscript: 9e9d56f1f99b: Verifying Checksum Dec 23 20:56:01 cloudml startupscript: 9e9d56f1f99b: Download complete Dec 23 20:56:01 cloudml startupscript: bdcb07accb69: Verifying Checksum Dec 23 20:56:01 cloudml startupscript: bdcb07accb69: Download complete Dec 23 20:56:02 cloudml startupscript: 227225d89949: Verifying Checksum Dec 23 20:56:02 cloudml startupscript: 227225d89949: Download complete Dec 23 20:56:02 cloudml startupscript: 2d8e1f2e409d: Verifying Checksum Dec 23 20:56:02 cloudml startupscript: 2d8e1f2e409d: Download complete Dec 23 20:56:02 cloudml startupscript: 25ed206e474f: Verifying Checksum Dec 23 20:56:02 cloudml startupscript: 25ed206e474f: Download complete Dec 23 20:56:02 cloudml startupscript: 6649046050df: Verifying Checksum Dec 23 20:56:02 cloudml startupscript: 6649046050df: Download complete Dec 23 20:56:06 cloudml startupscript: 0454c6c3871b: Verifying Checksum Dec 23 20:56:06 cloudml startupscript: 0454c6c3871b: Download complete Dec 23 20:56:09 cloudml startupscript: fce7c67b7824: Pull complete Dec 23 20:56:20 cloudml startupscript: 6f91e98067d1: Pull complete Dec 23 20:56:20 cloudml startupscript: 8378bed4dab2: Pull complete Dec 23 20:56:20 cloudml startupscript: b2f901dfbe7f: Pull complete Dec 23 20:56:39 cloudml startupscript: bdcb07accb69: Pull complete Dec 23 20:56:57 cloudml startupscript: 9e9d56f1f99b: Pull complete Dec 23 20:57:22 cloudml startupscript: 0454c6c3871b: Pull complete Dec 23 20:57:24 cloudml startupscript: 2d8e1f2e409d: Pull complete Dec 23 20:57:24 cloudml startupscript: 227225d89949: Pull complete Dec 23 20:57:26 cloudml startupscript: 25ed206e474f: Pull complete Dec 23 20:57:26 cloudml startupscript: 6649046050df: Pull complete Dec 23 20:57:26 cloudml startupscript: Digest: sha256:e171ec27130a697b0e2201fc064e2563c5dfad9d745f656b1abaf8aa4deae534 Dec 23 20:57:26 cloudml startupscript: Status: Downloaded newer image for gcr.io/api-project-773889352370/rwhales:latest 

那么有一些输出我不遵循

 Dec 24 02:58:43 cloudml startupscript: root@6c58c24fd46a:/# #015#033[Kroot@6c58c24fd46a:/# #015#033[Kroot@6c58c24fd46a:/# top#015 Dec 24 02:58:44 cloudml startupscript: #033[?1h#033=#033[?25l#033[H#033[2J#033(B#033[mtop - 02:58:44 up 6:03, 0 users, load average: 0.13, 0.10, 0.03#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:44 cloudml startupscript: Tasks:#033(B#033[m#033[39;49m#033[1m 2 #033(B#033[m#033[39;49mtotal,#033(B#033[m#033[39;49m#033[1m 1 #033(B#033[m#033[39;49mrunning,#033(B#033[m#033[39;49m#033[1m 1 #033(B#033[m#033[39;49msleeping,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mstopped,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mzombie#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:44 cloudml startupscript: %Cpu(s):#033(B#033[m#033[39;49m#033[1m 3.1 #033(B#033[m#033[39;49mus,#033(B#033[m#033[39;49m#033[1m 0.1 #033(B#033[m#033[39;49msy,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mni,#033(B#033[m#033[39;49m#033[1m 96.7 #033(B#033[m#033[39;49mid,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mwa,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mhi,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49msi,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mst#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:44 cloudml startupscript: KiB Mem :#033(B#033[m#033[39;49m#033[1m 53703824 #033(B#033[m#033[39;49mtotal,#033(B#033[m#033[39;49m#033[1m 53038784 #033(B#033[m#033[39;49mfree,#033(B#033[m#033[39;49m#033[1m 467560 #033(B#033[m#033[39;49mused,#033(B#033[m#033[39;49m#033[1m 197480 #033(B#033[m#033[39;49mbuff/cache#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:44 cloudml startupscript: KiB Swap:#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mtotal,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mfree,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mused.#033(B#033[m#033[39;49m#033[1m 53056464 #033(B#033[m#033[39;49mavail Mem #033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:44 cloudml startupscript: #033[K#015 Dec 24 02:58:44 cloudml startupscript: #033[7m PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND #033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:44 cloudml startupscript: #033(B#033[m 1 root 20 0 19868 2700 2152 S 0.0 0.0 0:00.02 bash #033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:44 cloudml startupscript: #033(B#033[m#033[1m 7 root 20 0 44804 3556 3092 R 0.0 0.0 0:00.00 top #033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:47 cloudml startupscript: #033[J#033[H#033(B#033[mtop - 02:58:47 up 6:03, 0 users, load average: 0.13, 0.10, 0.03#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:47 cloudml startupscript: Tasks:#033(B#033[m#033[39;49m#033[1m 2 #033(B#033[m#033[39;49mtotal,#033(B#033[m#033[39;49m#033[1m 1 #033(B#033[m#033[39;49mrunning,#033(B#033[m#033[39;49m#033[1m 1 #033(B#033[m#033[39;49msleeping,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mstopped,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mzombie#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:47 cloudml startupscript: %Cpu(s):#033(B#033[m#033[39;49m#033[1m 0.2 #033(B#033[m#033[39;49mus,#033(B#033[m#033[39;49m#033[1m 0.1 #033(B#033[m#033[39;49msy,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mni,#033(B#033[m#033[39;49m#033[1m 99.8 #033(B#033[m#033[39;49mid,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mwa,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mhi,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49msi,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mst#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:47 cloudml startupscript: KiB Mem :#033(B#033[m#033[39;49m#033[1m 53703824 #033(B#033[m#033[39;49mtotal,#033(B#033[m#033[39;49m#033[1m 53038372 #033(B#033[m#033[39;49mfree,#033(B#033[m#033[39;49m#033[1m 467540 #033(B#033[m#033[39;49mused,#033(B#033[m#033[39;49m#033[1m 197912 #033(B#033[m#033[39;49mbuff/cache#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:47 cloudml startupscript: KiB Swap:#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mtotal,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mfree,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mused.#033(B#033[m#033[39;49m#033[1m 53056668 #033(B#033[m#033[39;49mavail Mem #033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:47 cloudml startupscript: #033[K#015 Dec 24 02:58:47 cloudml startupscript: #015 Dec 24 02:58:47 cloudml startupscript: #015 Dec 24 02:58:47 cloudml startupscript: #033(B#033[m#033[1m 7 root 20 0 44772 3576 3092 R 0.0 0.0 0:00.00 top #033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:50 cloudml startupscript: #033[J#033[H#033(B#033[mtop - 02:58:50 up 6:03, 0 users, load average: 0.12, 0.10, 0.02#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:50 cloudml startupscript: #015 Dec 24 02:58:50 cloudml startupscript: %Cpu(s):#033(B#033[m#033[39;49m#033[1m 0.1 #033(B#033[m#033[39;49mus,#033(B#033[m#033[39;49m#033[1m 0.1 #033(B#033[m#033[39;49msy,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mni,#033(B#033[m#033[39;49m#033[1m 99.8 #033(B#033[m#033[39;49mid,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mwa,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mhi,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49msi,#033(B#033[m#033[39;49m#033[1m 0.0 #033(B#033[m#033[39;49mst#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:50 cloudml startupscript: KiB Mem :#033(B#033[m#033[39;49m#033[1m 53703824 #033(B#033[m#033[39;49mtotal,#033(B#033[m#033[39;49m#033[1m 53035472 #033(B#033[m#033[39;49mfree,#033(B#033[m#033[39;49m#033[1m 470412 #033(B#033[m#033[39;49mused,#033(B#033[m#033[39;49m#033[1m 197940 #033(B#033[m#033[39;49mbuff/cache#033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:50 cloudml startupscript: KiB Swap:#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mtotal,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mfree,#033(B#033[m#033[39;49m#033[1m 0 #033(B#033[m#033[39;49mused.#033(B#033[m#033[39;49m#033[1m 53053788 #033(B#033[m#033[39;49mavail Mem #033(B#033[m#033[39;49m#033(B#033[m#033[39;49m#033[K#015 Dec 24 02:58:50 cloudml startupscript: #033[K#015 Dec 24 02:58:50 cloudml startupscript: #015 Dec 24 02:58:50 cloudml startupscript: #015 Dec 24 02:58:50 cloudml startupscript: #015 Dec 24 02:58:52 cloudml startupscript: #033[J#033[?1l#033>#033[25;1H#015 Dec 24 02:58:55 cloudml startupscript: #033[?12l#033[?25h#033[Kroot@6c58c24fd46a:/# cat r#010#033[K#010#033[K#010#033[K#010#033[K#010#033[K#007ls#015 Dec 24 02:58:55 cloudml startupscript: bin core etc init#011lib64 mnt proc run#011srv tmp var#015 Dec 24 02:58:55 cloudml startupscript: boot dev home lib#011media opt root sbin#011sys usr#015 Dec 24 02:58:58 cloudml startupscript: root@6c58c24fd46a:/# cd ~#015 Dec 24 02:59:01 cloudml startupscript: root@6c58c24fd46a:~# cd Wh#007#010#033[K#010#033[K#010#033[K#010#033[K#010#033[K#007ls#015 Dec 24 02:59:12 cloudml startupscript: root@6c58c24fd46a:~# cd h#010#033[Kb#007in#007#015 Dec 24 02:59:12 cloudml startupscript: bash: cd: bin: No such file or directory#015 Dec 24 02:59:15 cloudml startupscript: root@6c58c24fd46a:~# ls#015 Dec 24 03:00:42 cloudml startupscript: root@6c58c24fd46a:~# cd#010#033[K#010#033[Kexit#015 Dec 24 03:00:42 cloudml startupscript: exit#015 

它看起来像docker集装箱退出? 为什么?

然后它尝试执行下一行

 Dec 24 03:00:42 cloudml startupscript: # github.com SSH-2.0-libssh_0.7.0 Dec 24 03:00:42 cloudml startupscript: # github.com SSH-2.0-libssh_0.7.0 

并没有引入git clone。

 Dec 24 03:00:43 cloudml startupscript: Cloning into 'WhalePhys'... Dec 24 03:00:43 cloudml startupscript: Host key verification failed.#015 Dec 24 03:00:43 cloudml startupscript: fatal: The remote end hung up unexpectedly Dec 24 03:00:43 cloudml startupscript: /tmp/tmp.kLCLG1mcLE: line 18: cd: WhalePhys: No such file or directory 

并退出。

我需要这个自主工作,所以我不能手动进入一个非常简单的指纹。 这似乎是最安全的方式进行,但它很难debugging,因为交互式似乎工作正常。

关于如何打开docker集装箱的想法,使用SSH密钥克隆git仓库? 任何人都可以提供洞察什么中间错误信息的意思?

交互式看起来像这样

 ben@cloudml:~$ #run docker container and pass keys ben@cloudml:~$ sudo docker run -it -v /home/ben/.ssh/:/root/.ssh/ gcr.io/api-project-773889352370/rwhales bin/bash root@9ae5ad5db1dd:/# root@9ae5ad5db1dd:/# #add git to known hosts? root@9ae5ad5db1dd:/# ssh-keyscan github.com >> ~/.ssh/known_hosts # github.com:22 SSH-2.0-libssh_0.7.0 # github.com:22 SSH-2.0-libssh_0.7.0 # github.com:22 SSH-2.0-libssh_0.7.0 root@9ae5ad5db1dd:/# root@9ae5ad5db1dd:/# #clonex root@9ae5ad5db1dd:/# git clone git@github.com:bw4sz/WhalePhys.git --depth 1 Cloning into 'WhalePhys'... remote: Counting objects: 1360, done. remote: Compressing objects: 100% (590/590), done. remote: Total 1360 (delta 772), reused 1323 (delta 755), pack-reused 0 Receiving objects: 100% (1360/1360), 63.94 MiB | 17.48 MiB/s, done. Resolving deltas: 100% (772/772), done. root@9ae5ad5db1dd:/# root@9ae5ad5db1dd:/# cd WhalePhys root@9ae5ad5db1dd:/WhalePhys#