Search code examples
macosdockerdocker-desktop

macOS: How to update Docker Desktop that's running on an external drive, without removing existing containers?


I have installed Docker Desktop 3.0 on my mac - on an external drive. I'm trying to uprade it to latest. I don't get prompted for them and I can't see any option to check for updates in the GUI. I'd rather not uninstall incase it removes the containers and the data I have set up. But maybe I won't lose them? can someone point me in the right direction? thanks.

enter image description here


Solution

  • The location of the files dosn't play role in the upgrade. What plays the major role role is the source version and target version. There are two ways to upgrade the Docker for Mac, and there will be described in detail below:

    1. Incremental upgrade
    2. Upgrade with rebuild (Export / Import)

    In the specific case of the upgrade from 3.03 to 3.3, the upgrade to 3.1 and 3.2 can be done as incremental, without need to export / import data, however the upgrade to 3.2.1 will require rebuild of the VM, so the export / import method will help to move the data to the new VM.

    Location of data

    The application dosn't contain the data for the containers. Docker for macOS is running on a virtual machine, and the data is stored on the virtual disk of the virtual machine.

    The raw data (the virtual disk) of the virtual machine is located in

    ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
    

    Where the 0 is for the 0th VM. By default it's only one VM, but it's better to check. You can find this information from the GUI from Preferences > Resources > Disk Image Location. Simple copy of the content of the data folder will preserve the virtual machine.

    Incremental Upgrade

    It's always recommended to do incremental upgrade by following the official release versions between your current version and the target version. The releass can be found in the release notes.

    The steps to upgrade are:

    1. Stop the docker application (from the menu, find the docker icon and select Quit Docker Desktop
    2. Make full backup of the ~/Library/Containers/com.docker.docker/Data
    3. Rename the application (you might need it to go back, in case the upgrade is not successful)
    4. Copy the new application in the destination and start it.

    This steps will be repeated for each minor version between the source version and target version. Some versions can be skipped, however it's not recommended.

    In case of problems you can use the troubleshooting guid.

    Upgrades with rebuild of the VM

    Be aware that upgrading the docker from certain older version to new version might require a rebuild of the virtual machine.

    In addition, sometimes the upgrade is not working properly and you will need to uninstall the application as described in the troubleshooting page.

    So before you proceed with the uninstall and rebuild of the VM, if you have data that it's important for you, it is highly recommendable to export the containers, volumes and images before the upgrade.

    You will need to make a list of all of the containers, images and volumes you want to move across to the new VM. Following docker commands will help:

    ~# docker ps -a
    ~# docker volume ls
    ~# docker image ls
    

    To export the information, you can use the docker export and docker image save. The following example will save the image or the container/volume to file called file.raw:

    ~# docker export <<volume name or contianer name>> > file.raw
    ~# docker image save <<image name>> > file.raw
    

    Once the Docker is installed (the latest version) and the VM is rebuild, to import the data back from the files, you will need to use:

    ~# docker import file.raw
    ~# docker image load file.raw