我正在使用cloudinit文件启动GCE服务器,该文件调用docker镜像。在启动时,拉动docker镜像失败,但是如果我在登录时运行相同的服务则成功。我希望它能在推出时发挥作用。
查看服务日志,似乎错误地为docker pull添加了docker.io
,因此失败了。
我有什么办法可以防止这种情况发生吗?在尝试使用docker之前,我是否需要等待或检查其他内容?
这是我的cloud-init文件:
#cloud-config
users:
- name: shinyuser
uid: 2000
write_files:
- path: /etc/systemd/system/shinyserver.service
permissions: 0644
owner: root
content: |
[Unit]
Description=Shiny server
[Service]
ExecStart=/usr/bin/docker run --name=vdshinyserver -p 80:3838 -v /home/shinyuser/shinyapps/:/srv/shiny-server/ -v /home/shinyuser/srv/shinylog/:/var/log/ rocker/shiny
ExecStop=/usr/bin/docker stop vdshinyserver
runcmd:
- systemctl daemon-reload
- systemctl start shinyserver.service
以下是日志:
mark@xxxshiny ~ $ sudo journalctl -u shinyserver
-- Logs begin at Wed 2016-10-05 08:39:06 UTC, end at Wed 2016-10-05 08:39:46 UTC. --
Oct 05 08:39:11 xxxshiny docker[1016]: Unable to find image 'rocker/shiny:latest' locally
Oct 05 08:39:26 xxxshiny docker[1016]: Pulling repository docker.io/rocker/shiny
Oct 05 08:39:31 xxxshiny docker[1016]: /usr/bin/docker: Tag latest not found in repository docker.io/rocker/shiny.
Oct 05 08:39:31 xxxshiny docker[1016]: See '/usr/bin/docker run --help'.
Oct 05 08:39:31 xxxshiny docker[1045]: Error response from daemon: No such container: vdshinyserver
mark@visit-dubai-shiny ~ $ sudo systemctl start shinyserver.service
mark@visit-dubai-shiny ~ $ sudo journalctl -u shinyserver
...
Oct 05 08:42:22 xxxshiny docker[1117]: Unable to find image 'rocker/shiny:latest' locally
Oct 05 08:42:23 xxxshiny docker[1117]: latest: Pulling from rocker/shiny
Oct 05 08:42:23 xxxshiny docker[1117]: a84f66826a7f: Pulling fs layer
Oct 05 08:42:23 xxxshiny docker[1117]: aaf7c0da390d: Pulling fs layer
...etc...
答案 0 :(得分:1)
我编辑了我的cloudinit,以匹配Docker documentation中的{cloud}以在文件中包含docker.service
的要求,现在它可以正常运行:
#cloud-config
users:
- name: shinyuser
uid: 2000
write_files:
- path: /etc/systemd/system/shinyserver.service
permissions: 0644
owner: root
content: |
[Unit]
Description=VisitDubai Shiny server for reporting
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker run --name=vdshinyserver -p 80:3838 -v /home/shinyuser/shinyapps/:/srv/shiny-server/ -v /home/shinyuser/srv/shinylog/:/var/log/ rocker/shiny
ExecStop=/usr/bin/docker stop vdshinyserver