34

I have a vanilla install of CoreOS (835.9.0) and it doesn't start the docker daemon on startup. It only starts when I SSH in and do eg docker ps.

How can i make the docker daemon automatically start on system boot?

When i say the docker daemon, i mean ps -ef | grep docker shows no processes until after i do docker ps

Chris
  • 1,281

4 Answers4

56

sudo systemctl enable docker did the trick.

Chris
  • 1,281
6

This is a bit old now, but I have started using cloud-init to do this on all new servers. I have a saved cloud-init script I use for all my servers. Part of it contains:

#cloud-config
coreos:
  units:
    - name: "docker.service"
      command: "start"
      enable: true

This will enable the docker service and start it on first and each boot.

2

As already explained in this comment by Rob, docker is socket activated. That means that the deamon does not start unless it is called. The existing answers here work, but CoreOS recommends a different approach.

The recommended way to do this, according to the CoreOS documentation is to create a service for your own app which in turn requires the Docker service:

/etc/systemd/system/myapp.service:

[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 "trap 'exit 0' INT TERM; while true; do echo Hello World; sleep 1; done"

[Install]
WantedBy=multi-user.target

And have that service start automatically instead:

$ sudo systemctl enable /etc/systemd/system/myapp.service
$ sudo systemctl start hello.service

The example use-case is to update the container to the latest version once the service starts and the advanced example also registers the service in etcd. Read the CoreOS documentation for more background information.

1

I'm using Docker Swarm, so I don't have a specific app for systemd to be responsible for... I just need docker to start on boot. This is the solution I worked out.

Put this /etc/systemd/system/poke-docker.service:

[Unit]
After=default.target

[Service]
Type=oneshot
ExecStart=/usr/bin/docker version
RemainAfterExit=yes

[Install]
WantedBy=default.target

And then just systemctl enable poke-docker to set it up to trigger on each boot, near the end of the startup sequence. The docker version command talks to the docker daemon, triggering the socket and starting the docker service itself.

I tried the systemctl enable docker trick in the other answer, and while it worked at first, it appears to have caused a thundering herd situation of some sort where docker was apparently trying to do a whole lot and failing miserably. I suspect this is the "blocking the boot chain" behavior mentioned in the comments there.