I created a droplet with the following configuration:
512MB Ram 20GB SSD Disk Amsterdam 3 CoreOS CoreOS (beta) 494.0.0
CoreOS was subsequently updated to 494.1.0.
Since I don’t need a cluster, I didn’t provide a cloud-config.
Then I added the following systemd script in /etc/systemd/system/hello.service (copied from the official CoreOS tutorial):
[Unit]
Description=MyApp
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill busybox1
ExecStartPre=-/usr/bin/docker rm busybox1
ExecStartPre=/usr/bin/docker pull busybox
ExecStart=/usr/bin/docker run --name busybox1 busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done"
[Install]
WantedBy=multi-user.target
I ran ‘sudo systemctl enable hello’ and ‘sudo systemctl start hello’. Everything worked perfectly.
Then I rebooted the machine, and this happened:
systemd[1]: Starting MyApp...
docker[478]: busybox1
docker[600]: busybox1
docker[610]: Pulling repository busybox
docker[610]: Get https://index.docker.io/v1/repositories/library/busybox/images: dial tcp: lookup index.docker.io: connection refused
systemd[1]: hello.service: control process exited, code=exited status=1
systemd[1]: Failed to start MyApp.
systemd[1]: Unit hello.service entered failed state.
I destroyed and recreated the droplet, with exactly the same result.
I tried the same approach and script locally with Vagrant as well as on Google Computing Engine, and it worked as expected both times.
Am I doing something wrong, or does the problem lie with Digital Ocean?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Adding Restart and RestartSec fixed the issue:
# Restart after crash
Restart=always
# Give the service 10 seconds to recover after the previous restart
RestartSec=10s
Read more here
This comment has been deleted
For the ones still hitting this issue, use systemd-networkd-wait-online.service instead of network-online.target. Here is my unit which works well:
[Unit]
After=early-docker.service systemd-networkd-wait-online.service
Requires=early-docker.service systemd-networkd-wait-online.service
Before=early-docker.target
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.