49

I was trying to experiment with docker, Ubuntu 14.04, 64-bit. I managed to run an image, and I gave it the path on one of my removable drives, /media/Drive1.

Now, whenever I reboot, I see there is a /media/Drive1 with only a docker directory inside it, and the actual drive which should be Drive1 ends up mounted on /media/Drive11, and this happens every reboot - even when I unmount these drives, and do a sudo rm -rfv /media/Drive1 before rebooting!

So something probably creates /media/Drive1 before it is fully mounted, and I guess that something is docker, because when I boot, I have:

$ ps axf | grep docker
 2085 ?        Ssl    0:00 /usr/bin/docker -d

So, how can I disable the docker autostart, so it doesn't interfere with the mounting of external USB drives at boot?

4 Answers 4

85

On the systems since Ubuntu 16.04+ (where OS uses systemd), according to the doc, autostart on boot can be turned off by:

$ sudo systemctl disable docker.service
$ sudo systemctl disable docker.socket

or as @Burak said in the comment, here is the one liner command:

sudo systemctl disable docker.service docker.socket

Note that if you do not disable the socket as well as the service then the service will get started anyways as the socket depends on it.

4
  • 8
    In my case, I had to disable docker-volume-local-persist.service and docker.socket as well. To list any docker service in systemd, type: systemctl list-unit-files | grep -i docker
    – chefarov
    Commented Mar 8, 2018 at 16:31
  • I had to reinstall docker after this because docker-compose up wouldn't work anymore
    – Taylor
    Commented Jan 7, 2021 at 13:38
  • You can use one-liner sudo systemctl disable docker.service docker.socket
    – Burak
    Commented Aug 21, 2021 at 13:13
  • @Taylor FYI you just had to re-enable the service: sudo systemctl enable docker.service docker.socket
    – Enrico
    Commented Feb 16, 2022 at 18:40
9

Ok, I think I managed to get it working, following How to enable or disable services?:

sudo bash -c 'echo manual | sudo tee /etc/init/docker.override'

Hope that was it...

2

This is for recent Ubuntu releases using systemctl.

To disable on boot, use systemctl disable as @Burak said:

sudo systemctl disable docker.service docker.socket

This will have the side-effect of stopping Docker from working at all after a reboot, as @Taylor found. You will get an error like this:

~$ sudo docker container ls
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

To start the Docker service in a script or at the prompt without re-enabling it to start at boot, use systemctl start:

sudo systemctl start docker.service

You can then use docker or docker-compose as normal, and it will still not automatically restart on boot.

0

I think the best way is to apply mask to the service:

sudo systemctl mask docker
1
  • 2
    Which will disable the docker service completely, until you manually "unmask" it.
    – John Mee
    Commented Sep 3, 2021 at 4:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .