2 How to use
neil edited this page 7 months ago

Definitions

  • Remote image: An image you can download on DockerHub.
  • Local image: An image you build locally, which isn't on DockerHub. It is generally a child of a remote image.
  • Child image: An image that depends on another (through the FROM instruction in your Dockerfile).

Summary

Here's a list of what you need to prepare for this script:

  • A list of your images and their children images (specified in services.json)
  • One build script for each local image.
  • One restart script for each running container that needs to be restarted with an updated image.

Listing your images

You must list all your images and their children in services.json. Here's how it looks like:

[    
    {
        "name": "allinurl/goaccess",
        "tag": "latest"
    },
    {
        "name": "library/nginx",
        "tag": "stable-alpine",
        "children": [
            {
                "name": "local/nginx",
                "tag": "latest",
                "service": true
            }
        ]
    }
]
  • The name and tag keys are mandatory for each entry.
  • The children key is an optional array containing as many child images you need. Children images are probably local images.
  • All local images must begin with local/, so the script can recognize them. You can change this prefix by editing the script (LOCAL_PREFIX variable).
  • The service key is an optional boolean. If set to true, updating the image will run a script (used to restart the containers using an old version of the image).

Build scripts

By default, you must place your build scripts in the build folder. You can change this by editing the BUILD_SCRIPTS_DIR variable in the script.

The build script must have the same name as your image, removing the prefix and adding .sh suffix. Ex.: local/nginx's script would be nginx.sh.

The script must build the image (usually with docker build), but can also trigger any custom action you need.

Restart scripts

All your restart scripts must be located in the restart folder. You can change this by editing the RESTART_SCRIPTS_DIR variable in the script.

A restart script basically restarts your container(s) which uses a specific image, by executing custom commands (docker run / docker-compose), to make the container use your new, updated image.

The restart script must have the same name as your image, removing the prefix and adding .sh suffix. Ex.: local/nginx's script would be nginx.sh.

When the script ends, the old image shouldn't be in use anymore (unless it has children), so it will be deleted automatically.

Running the script

Once everything is ready, just run the script (./update-images.py).

The script should read the services.json file and check for updates. If it finds for updates, you will be prompted for confirmation.