I am starting a GCE server with a cloudinit file, that calls a docker image. On startup, pulling the docker image fails, but if I run the same service upon logging in it succeeds. I would like it to work upon launch.
Looking at the service logs, it seems that it is incorrectly prefixing the docker pull with docker.io
and so failing the job.
Is there something I could be doing to prevent this? Do I perhaps need to wait or check for something else to load before trying the docker pull?
Here is my cloud-init file:
#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
And here are the logs:
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...
I edited my cloudinit to match that at the Docker documentation to include a requirement of docker.service
in the file, and it now works:
#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