DockerFile and docker-compose (Homeassistant and Node-red Nodes)

I just did some quick testing and I believe you have two problems here, one is straightforward and the other is actually very subtle.


The first problem is that Compose does not automatically rebuild a service's image if the image already exists. When you run the service for the first time Compose will build the image using the dockerfile, but on subsequent runs it will just re-use the already existing image. The docs are actually frustratingly unclear on this, but the command output when running docker-compose up from your sample file is more helpful:

...
WARNING: Image for service node-red was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
...

I believe that in order to get the behavior you're looking for you should modify your systemd service to use the --build flag which will trigger a rebuild regardless of whether an image with the same tag exists or not.


The second problem I believe you're running into (this is also based on a quick test I ran using a modified version of the sample configs) is that you are overwriting your base image tag on each build.

According to the Compose file reference section on the build directive (third block down at this link) when both build and image are specified for a service, as yours are, docker will build the image according to the build directive and then tag it using the value of image directive. Because your image directive in the docker-compose file and the FROM directive in the dockerfile use the same tag you are telling Docker to tag your locally built image with the same name as the base image your dockerfile pulls from.

This means that each rebuild of the container (after the first build) will in fact be using the previous version of itself as the base container, rather than using the nodered/node-red from the upstream.

To fix this just change the value of the image directive in the compose file to something else; e.g. local-custom-node-red