5

While following the systemd guide I ran into an issue with this example configuration:

[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

If I run "systemctl start hello" while the system is running the docker will boot, but if I enable "hello.service" to boot on start through systemd and reboot the machine I receive this error:

-- Reboot --
Mar 15 01:17:44 general systemd[1]: Starting MyApp...
Mar 15 01:17:47 general docker[510]: Error response from daemon: No such container: busybox1
Mar 15 01:17:47 general docker[510]: time="2015-03-15T01:17:47Z" level="fatal" msg="Error: failed to kill one or more containers"
Mar 15 01:17:47 general docker[637]: Error response from daemon: No such container: busybox1
Mar 15 01:17:47 general docker[637]: time="2015-03-15T01:17:47Z" level="fatal" msg="Error: failed to remove one or more containers"
Mar 15 01:17:47 general systemd[1]: hello.service: control process exited, code=exited status=1
Mar 15 01:17:47 general systemd[1]: Failed to start MyApp.
Mar 15 01:17:47 general systemd[1]: Unit hello.service entered failed state.
Mar 15 01:17:47 general systemd[1]: hello.service failed.
Mar 15 01:17:47 general docker[673]: Pulling repository busybox
Mar 15 01:17:47 general docker[673]: time="2015-03-15T01:17:47Z" level="fatal" msg="Get https://index.docker.io/v1/repositories/library/busybox/images: dial tcp: lookup index.docker.io: connection refused"

Any clue what I'm doing wrong?

migrated from serverfault.com Mar 21 '15 at 11:11

This question came from our site for system and network administrators.

  • 1
    Wait. Why was this down voted? Constructive critisizm should be manditory for down voting because frankly I have no clue if I posted in the wrong place or if I broke a rule I didn't realize I broke. Also i included digital ocean in case it could be an issue related to how their set up works. I imagine coreos would work by default, but I could be wrong. – Lethjakman Mar 16 '15 at 4:47
5

If you want to run this on boot, you should depend on the network-online.target service. You need to ensure that networking is up before running the docker pull command. See "Running Services After the Network is up" from the systemd documentation for more info.

The following works for me:

[Unit]
Description=MyApp
Requires=docker.service network-online.target
After=docker.service network-online.target

[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 actually tried network-online at one point already. I figured that would be a dependency of docker. Odd thing is that I copied your exact config and it still doesn't load and throws the same exact error. Thank you for your feedback, this is leading me to believe that this may not be a configuration issue of my own. – Lethjakman Mar 17 '15 at 3:12
1

I tried out the suggested:

Requires=docker.service network-online.target
After=docker.service network-online.target

But it didn't work. I got:

-- Reboot --
Feb 09 23:20:24 coreos-512mb-fra1-01 systemd[1]: Starting New Relic Linux Server Monitor (nrsysmond)...
Feb 09 23:20:24 coreos-512mb-fra1-01 docker[782]: Failed to kill container (nrsysmond): Error response from daemon: Cannot kill container nrsysmond: Container c608c10f44c06c550492e872773b0d5a59a7b86e639f63487f6186983a4f786b is not running
Feb 09 23:20:25 coreos-512mb-fra1-01 docker[787]: nrsysmond
Feb 09 23:20:25 coreos-512mb-fra1-01 docker[794]: Pulling repository docker.io/newrelic/nrsysmond
Feb 09 23:20:25 coreos-512mb-fra1-01 docker[794]: Error while pulling image: Get https://index.docker.io/v1/repositories/newrelic/nrsysmond/images: dial tcp: lookup index.docker.io: Temporary failure in name resolution
Feb 09 23:20:25 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Control process exited, code=exited status=1
Feb 09 23:20:25 coreos-512mb-fra1-01 systemd[1]: Failed to start New Relic Linux Server Monitor (nrsysmond).
Feb 09 23:20:25 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Unit entered failed state.
Feb 09 23:20:25 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Failed with result 'exit-code'.

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

It's not elegant but works. Here is the log:

Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: Starting New Relic Linux Server Monitor (nrsysmond)...
Feb 09 23:23:57 coreos-512mb-fra1-01 docker[792]: Failed to kill container (nrsysmond): Error response from daemon: Cannot kill container nrsysmond: Container 31fb78809
Feb 09 23:23:57 coreos-512mb-fra1-01 docker[797]: nrsysmond
Feb 09 23:23:57 coreos-512mb-fra1-01 docker[804]: Pulling repository docker.io/newrelic/nrsysmond
Feb 09 23:23:57 coreos-512mb-fra1-01 docker[804]: Error while pulling image: Get https://index.docker.io/v1/repositories/newrelic/nrsysmond/images: dial tcp: lookup ind
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Control process exited, code=exited status=1
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: Failed to start New Relic Linux Server Monitor (nrsysmond).
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Unit entered failed state.
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Failed with result 'exit-code'.
Feb 09 23:24:08 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Service hold-off time over, scheduling restart.
Feb 09 23:24:08 coreos-512mb-fra1-01 systemd[1]: Stopped New Relic Linux Server Monitor (nrsysmond).
Feb 09 23:24:08 coreos-512mb-fra1-01 systemd[1]: Starting New Relic Linux Server Monitor (nrsysmond)...
Feb 09 23:24:08 coreos-512mb-fra1-01 docker[869]: Failed to kill container (nrsysmond): Error response from daemon: Cannot kill container nrsysmond: No such container: 
Feb 09 23:24:08 coreos-512mb-fra1-01 docker[875]: Failed to remove container (nrsysmond): Error response from daemon: No such container: nrsysmond
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: latest: Pulling from newrelic/nrsysmond
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: 6ffe5d2d6a97: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: f4e00f994fd4: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: e99f3d1fc87b: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: a3ed95caeb02: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: a3ed95caeb02: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: 65cdb07f703d: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: a3ed95caeb02: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: Digest: sha256:c184f97452321baa0b0ee4ee402e3aaa204f041beb7a71a347db6c4efecba07f
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: Status: Image is up to date for newrelic/nrsysmond:latest
Feb 09 23:24:10 coreos-512mb-fra1-01 systemd[1]: Started New Relic Linux Server Monitor (nrsysmond).

Since I got this issue on DigitalOcean CoreOS, I searched for help in their resources. There is a thread related to this issue. It suggests this:

After=early-docker.service systemd-networkd-wait-online.service
Requires=early-docker.service systemd-networkd-wait-online.service
Before=early-docker.target

But those lines made Docker hang/freeze. I had to kill all processes related to my service and then restart the Docker service to make it responsive again.


Docker version:

docker -v
Docker version 1.10.0, build e21da33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy