Score:0

Docker starting before Virtualbox shares are mounted

cx flag

My setup: Virtualbox with a Windows Host and Ubuntu Server guest. Ubuntu is now 21.04 but the issue existed before upgrade from 20.04. And on the Ubuntu Server I run Docker.

The issue: The shares from virtualbox, which I think are mounted by the Vbox guest addons are not mounted until after Docker starts. The containers start OK as their config is on /home which is a local drive, however they have data on a share. Because Docker starts before the shares are mounted the containers bind to the mountpoint as a directory rather than a mount and they can write to the disk there filling up the root filesystem with invisible files.

I hadn't made any changes recently other than keeping up with Ubuntu updates but I feel like I might have put a sleep somewhere in the past to get around this. I could look to do this again but it seems rather inelegant and I wondered if there might be a better way through systemd or otherwise.

I've tried a number or systemd directives without any luck. RequiresMountsFor and ConditionPathIsMountPoint were the two that I thought might work. I also tried to tell the docker service to start after the vbox guest service but this didn't work either.

Any suggestions?

Jeff Schaller avatar
ru flag
Telling docker to start after vbox seems like the right solution; could you [edit] your question to describe what you did for that and what the results were? The "start" timestamps for each service should indicate whether they started in the desired sequence or not.
cx flag
Thanks, I'll go through the steps I took again and document them in enough detail to update my post above. Thanks for your response. I'm convinced this can be solved in systemd but the steps I took previously didn't work.
Score:1
cx flag

The solution was to override the systemd service file for containerd.

run

    systemctl edit containerd

add the following in the place specified in the comments.

    [Unit]
    After=
    After=network.target local-fs.target vboxadd-service.service
    Requires=vboxadd-service.service

The first After= clears that directive ready for the new one. Both After and Requires are needed. Save this file and then restart host.

Works without issue and confirmed by 'systemd-analyse plot', which is a very useful command for interrogating your systemd run order. This method will survive software updates

Jeff Schaller avatar
ru flag
You'll want to make that change in the /etc/systemd/system/ version of the file, since the /lib/systemd one will be overwritten during future upgrades.
cx flag
That is just a symlink
cx flag
/etc/systemd/system/multi-user.target.wants/containerd.service -> /lib/systemd/system/containerd.service Should I break the link and copy the file and edit?
cx flag
Actually found this too using 'systemctl edit containerd'
Jeff Schaller avatar
ru flag
You don't want to edit the symlink in multi-user.target.wants, no -- you want to edit (or create) a file named `/etc/systemd/system/containerd.service`; perhaps copy the original one from /lib and make the changes?
cx flag
I've done it with an override now. I'll update the main post with final solution
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.