If you have any exposed (non-random) ports, you will need to stop the old container first and start a new one. You can use something like Watchtower if you push your images to a registry. If you do everything locally, I would recommend using Docker Compose to manage the containers. That way you can run an idempotent command and it will always be up to date.
There is no great way to cache bust in Docker Compose that I’m aware of, but I will give you two solutions.
Option 1: Use static versions for all of your dependencies.
Then when there is an update you change the version explicitly in the Dockerfile and everything updates as expected
Dockerfile
FROM domoticz/domoticz:v1.0.0 # I recommend a static version here to help with cache-busting when you update the base image
RUN apt-get update && apt-get upgrade -y && apt-get install etherwake==<etherwake_version> wget==<wget_version> ... -y
And then you have a Docker-compose.yml file like this:
services:
web:
build:
context: .
When you need to update, change your Dockerfile so maybe it says
FROM domoticz/domoticz:v1.0.0 # I recommend a static version here to help with cache-busting when you update the base image
-RUN apt-get update && apt-get upgrade -y && apt-get install ... wget==1.20.0-1ubuntu1 ... -y
+RUN apt-get update && apt-get upgrade -y && apt-get install ... wget==1.20.3-1ubuntu1 ... -y
And you can run docker-compose up -d --build
to automatically replace the running container with a newly built image
The downside here is that you have to manually look up and manage versions.
Option 2: Use “evergreen” versions and manually cache-bust.
Your Dockerfile would look like this:
FROM domoticz/domoticz:latest
RUN apt-get update && apt-get upgrade -y && apt-get install etherwake wget curl php-cli php-xml php-soap -y
Your docker-compose.yml
file will look like this:
services:
web:
image: coolness
When you want to update, just run docker build . -t coolness --no-cache --pull && docker-compose up -d
.
**The downside here is that no matter if there is a dependency update or not, your resulting image will always change (at least it did in my tests) and thus docker-compose up -d
will always replace your container with a new container. **