Table of contents

Introduction

In this blog post, we'll go over how to set up a TimeMachine server with Docker. TimeMachine is a backup utility built into Mac computers that allows users to backup their full system to an external storage. We can quickly establish a TimeMachine server on any platform, including Windows and Linux, by utilising Docker.

This post will walk you through the process of creating a Docker container and configuring a TimeMachine server with Docker. You will have a fully functional TimeMachine server that you can use to backup your Mac machines by the end of this tutorial.

Setting up Docker on your machine

ℹ️
You can skip this part if you already have Docker installed.

On Mac you can get the Docker Desktop app from the official website and install it by following the on-screen instructions. Once the installation is done, you can start using Docker by opening the app.

Install on Mac
How to install Docker Desktop on Mac

On Windows, go to the official website and download the Docker Desktop app for Windows. Then, run the installer. Follow the on-screen instructions to set up Docker on your computer. Once the installation is done, you can use Docker by opening the Docker Desktop app from the Start menu.

Install on Windows
How to install Docker Desktop for Windows

On Linux distributions have different ways of installing software. In general, you can use the package manager for your distribution to install Docker. On Ubuntu, you can install it with the command "sudo apt-get install docker." Once the installation is done, run the command "docker" in your terminal to start using Docker.

Install on Linux
How to install Docker Desktop on Linux

Container setup

Create a docker-compose.yml file anywhere, for example in /srv/timemachine.

version: '3.3'
services:
    timemachine:
        restart: unless-stopped
        container_name: timemachine
        network_mode: host
        environment:
            - ADVERTISED_HOSTNAME=
            - CUSTOM_SMB_CONF=false
            - CUSTOM_USER=false
            - DEBUG_LEVEL=1
            - 'MIMIC_MODEL=TimeCapsule8,119'
            - EXTERNAL_CONF=
            - HIDE_SHARES=no
            - TM_USERNAME=timemachine
            - TM_GROUPNAME=timemachine
            - TM_UID=1000
            - TM_GID=1000
            - PASSWORD=timemachine
            - SET_PERMISSIONS=false
            - SHARE_NAME=TimeMachine
            - SMB_INHERIT_PERMISSIONS=no
            - SMB_NFS_ACES=yes
            - SMB_METADATA=stream
            - SMB_PORT=445
            - 'SMB_VFS_OBJECTS=acl_xattr fruit streams_xattr'
            - VOLUME_SIZE_LIMIT=0
            - WORKGROUP=WORKGROUP
        volumes:
            - '/path/to/timemachine/backup:/opt/timemachine'
            - 'timemachine-var-lib-samba:/var/lib/samba'
            - 'timemachine-var-cache-samba:/var/cache/samba'
            - 'timemachine-run-samba:/run/samba'
        image: 'mbentley/timemachine:smb'

Make sure to update /path/to/timemachine/backup to the location where your TimeMachine backups will be kept. Change the default PASSWORD option as well; otherwise, someone on your network might be able to access your TimeMachine backup. Run the following command after creating the file:

docker compose up -d
Start the container in detached mode

Connecting Mac to the TimeMachine server

To connect a Mac to a Time Machine server, you will need to first make sure that the Time Machine server is set up and properly configured. Once this is done, follow these steps on your Mac:

  1. Open System Preferences by clicking on the Apple icon in the top-left corner of your screen and selecting "System Preferences."
  2. Click on the "Time Machine" icon.
  3. Click on the "Select Backup Disk" button.
  4. Select the Time Machine server from the list of available disks.
  5. If prompted, enter the username and password for the Time Machine server.
  6. Click on the "Use for Backup" button to begin the backup process.

Your Mac will now back up to the Time Machine server automatically every hour, as long as the Mac and the server are on the same network and the Mac is connected to a power source.

Tips and troubleshooting

Static IP address

When hosting the TimeMachine server on a server, it's a good idea to give it a static IP address or hostname. Otherwise, when the server is rebooted, it might get a new IP address from DHCP and TimeMachine might not be able to find it automatically, in which case you'll need to connect to it again using the server's new IP.

Can't find TimeMachine server

If you can't find your TimeMachine server on the list, open Finder, then from the context menu choose: Go -> Connect to Server...

Type in: smb://your-server-ip then click "Connect".

You will be asked for username and password to the TimeMachine server. Username: timemachine, password is what you defined in the environment PASSWORD variable.

Now, go back to TimeMachine preferences:

Now, select your TimeMachine server, and click Use Disk. That's it! Your server is now ready.

Conflicts with already running SMB server

If you're already running a Samba server on your machine, which was also the case for me, then the easiest option is to:

  1. Remove the --net=host option from docker-compose.yml
  2. Expose the ports manually, like this: 192.168.1.108:445:445, make sure to use your server's IP address instead of 192.168.1.108.
  3. Add another IP address to your host machine, you can do that even if you have one physical network card.
  4. Change /etc/samba/smb.conf and add interfaces = 192.168.1.109

Sample config with manually exposed ports:

version: '3.3'
services:
    timemachine:
        restart: always
        container_name: timemachine
        hostname: timemachine
        ports:
            - '192.168.1.108:445:445'
        environment:
            - ADVERTISED_HOSTNAME=
            - CUSTOM_SMB_CONF=false
            - CUSTOM_USER=false
            - DEBUG_LEVEL=1
            - HIDE_SHARES=no
            - EXTERNAL_CONF=
            - 'MIMIC_MODEL=TimeCapsule8,119'
            - TM_USERNAME=timemachine
            - TM_GROUPNAME=timemachine
            - TM_UID=1000
            - TM_GID=1000
            - PASSWORD=“password”
            - SET_PERMISSIONS=false
            - SHARE_NAME=TimeMachine
            - SMB_INHERIT_PERMISSIONS=no
            - SMB_NFS_ACES=yes
            - SMB_METADATA=stream
            - SMB_PORT=445
            - 'SMB_VFS_OBJECTS=acl_xattr fruit streams_xattr'
            - VOLUME_SIZE_LIMIT=0
            - WORKGROUP=WORKGROUP
        volumes:
            - '/path/to/timemachine/backup:/opt/timemachine'
            - 'timemachine-var-lib-samba:/var/lib/samba'
            - 'timemachine-var-cache-samba:/var/cache/samba'
            - 'timemachine-run-samba:/run/samba'
        image: 'mbentley/timemachine:smb'

If you don't want to expose the ports manually one by one, you can also use macvlan as explained here:

GitHub - mbentley/docker-timemachine: Docker image to run netatalk (compatible Time Machine for OS X)
Docker image to run netatalk (compatible Time Machine for OS X) - GitHub - mbentley/docker-timemachine: Docker image to run netatalk (compatible Time Machine for OS X)
Conflicts with Samba and/or Avahi on the Host