Saturday, February 9, 2019

Docker: update a container but take a backup first

You have ever downloaded a Docker image on your Synology and created a container out of it. Now like with the Unifi Controller, the software inside gets updated, so you also need to update the corresponding image. It's safe to take a backup of your container first before continuing.

Backup and restore of a container

  1. List the container you want to backup (the container must be running)
  2. docker ps
    Output:
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES 78727078a04b        debian:8            "/bin/bash"         13 seconds ago      Up 11 seconds                           unifi
  3. Take a snapshot of the running state
  4. docker commit -p  78727078a04b  unifi-20190209
    e09f9ac65c8b3095927c14ca0594868f73831bde0800ce66415afeb91aea93cf
  5. Verify that a snapshot has been stored with your images
  6. docker images
    REPOSITORY                      TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    unifi-20190209                  latest              e09f9ac65c8b        39 seconds ago      125.1 MB
  7. Save as a tar and archive, just in case
  8. docker save -o /volume1/docker/unifi/backups/unifi-20190209.tar unifi-20190209
    user:/volume1/docker/unifi/backups# ls -lh
    total 536M
    -rw------- 1 root root 536M Feb  9 08:59 unifi-20190209.tar
  9. If you want to restore, do a login first and then push the image
  10. docker login
    docker push unifi-20190209

Update a container on your Synology

  1. Login to your Synology DSM and go to the Docker app
  2. Go to the 'Image' repository. Check for the image that you started from and verify the tag you used (e.g. jacobalberty/unifi:stable)
  3. Go to the 'Container' part and stop the container that you want to update
  4. Go to the 'Registry' part and search for the image. When you found the corresponding image (e.g. jacobalberty/unifi), right click and choose 'Download this image'. You will start seeing the image being downloaded as the number 1 will appear next to 'Image'. Wait until the download is completed.
  5. Go back to the 'Container' part, select the container (it is still in stopped state). Click on 'Action' and click on 'Clear'. Do not click on Delete. The container will dissapear and reappear.
  6. Once it reappears, you can start it again.
More screenshots here.

No comments:

Post a Comment