Problem changing docker directory to USB SSD

I have followed the instructions in this thread, more specifically the JSON file in /etc/docker, but I have a problem. I have moved everything to /media/pi/MP3/Docker/Docker-System, which is on a 2 TB SSD, which is a lot faster than the regular SSD card. But If I use the regular systemd startup, Docker will load before fstab most of the time, so I will have two MP3 in /media/pi/, one that resides on the SSD card and has a Docker directory, and one that is the SSD with the files I want to use.

I have tried a few solutions.

  1. RequiresMountsFor=/media/pi/MP3 That gives me this Unit:
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
RequiresMountsFor=/media/pi/MP3
Requires=docker.socket

Docker does not start at all, it errors out without any meaningful explanation in status or journalctl:

× docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; preset: enabl>
Active: failed (Result: exit-code) since Thu 2024-08-01 21:08:13 CEST; 41s>
TriggeredBy: × docker.socket
Docs: https://docs.docker.com
Process: 1969 ExecStartPre=/bin/sleep 10 (code=exited, status=0/SUCCESS)
Process: 1985 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/contain>
Main PID: 1985 (code=exited, status=1/FAILURE)
CPU: 191ms

aug. 01 21:08:13 MadMax systemd[1]: docker.service: Scheduled restart job, rest>
aug. 01 21:08:13 MadMax systemd[1]: Stopped docker.service - Docker Application>
aug. 01 21:08:13 MadMax systemd[1]: docker.service: Start request repeated too >
aug. 01 21:08:13 MadMax systemd[1]: docker.service: Failed with result 'exit-co>
aug. 01 21:08:13 MadMax systemd[1]: Failed to start docker.service - Docker App>

  1. Disable docker.socket and docker.service and add a docker.timer, with a 10 second delay. and adding ExecStartPre=/bin/sleep 10 to the docker.service file. Both give me this:
 × docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; disabled; preset: enabled)
     Active: failed (Result: exit-code) since Thu 2024-08-01 21:01:11 CEST; 25s ago
TriggeredBy: × docker.socket
             ● docker.timer
       Docs: https://docs.docker.com
    Process: 1992 ExecStartPre=/bin/sleep 10 (code=exited, status=0/SUCCESS)
    Process: 2008 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
   Main PID: 2008 (code=exited, status=1/FAILURE)
        CPU: 207ms

aug. 01 21:01:11 MadMax systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
aug. 01 21:01:11 MadMax systemd[1]: Stopped docker.service - Docker Application Container Engine.
aug. 01 21:01:11 MadMax systemd[1]: docker.service: Start request repeated too quickly.
aug. 01 21:01:11 MadMax systemd[1]: docker.service: Failed with result 'exit-code'.
aug. 01 21:01:11 MadMax systemd[1]: Failed to start docker.service - Docker Application Container Engine.
~

Can somebody please give me a hint to what I should do to get this working? My images take too much space, so I really need them to be on the SSD.

Check older logs using journalctl. I guess you had a better error message but then the systemd service restarted too many times and now you only see that it cannot be restarted because it already tried too many times. You can stop the service completely and wait some minutes then try again. But you can run the dockerd command manually. The one that you can see in the ExecStart line. That would give you the error message without dealing with systemd.

Did you also create a mount unit?

Thank you very much for answering, and incredibly fast! :+1: Weirdly enough I get this error mesage:

sudo /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
INFO[2024-08-01T21:19:37.782091590+02:00] Starting up
failed to load listeners: no sockets found via socket activation: make sure the service was started by systemd

And socket is running:

pi@MadMax:~ $ systemctl status docker.socket
● docker.socket - Docker Socket for the API
Loaded: loaded (/lib/systemd/system/docker.socket; enabled; preset: enable>
Active: active (listening) since Thu 2024-08-01 21:18:58 CEST; 28s ago
Triggers: ● docker.service
Listen: /run/docker.sock (Stream)
Tasks: 0 (limit: 3910)
CPU: 1ms
CGroup: /system.slice/docker.socket

And about the mount unit, no I did not know about that. And I’m afraid I don’t really understand what that is. I have this in fstab to mount the SSD, I thought that was enough:

PARTUUID=F0A80AB0A80A74FE /media/pi/MP3 ntfs-3g defaults,nofail,noatime 0 0

I’m guessing here, but since Docker needs containerd, you could check if that runs as well.

Actually that was a guess as well, so that might not be the solution. I never used the RequiresMountsFor parameter. I just found the issue and came to the conclusion too quickly. But as it is pointed out in the comments, that mount unit would mount the folder as an alternative to the fstab file.

On the other hand, your line from fstab shows that the filesystem on your SSD is ntfs. That will not work. So Docker probably fails because of the wrong filesystem. You will need a compatible filesystem for Linux, not a Windows filesystem.

You can read about the supported “backing filesystems” here

https://docs.docker.com/storage/storagedriver/select-storage-driver/#supported-backing-filesystems

Thanks again! I just chekced and containerrd is running. But I guess the file system is the problem, then. I will partition the SSD and create an ext4 partition for the Docker files.

To round out the topic: When I created a 40 gig ext4 as the first partition on the SSD, RequiresMountsFor=/media/pi/Docker/Docker-System seems to work without a hitch. Thanks again for the help, @rimelek!