`docker-compose`: keep old container running until new one starts?

Hello,

I use PiHole successfully through Docker for a while now and have zero complaints. My only problem is that when it gets updated, the previous container gets killed and the new one always needs 30 seconds to start. During that time DNS resolution in my home network doesn't work.

It's not a huge annoyance, obviously, but I was wondering if we can get an example docker-compose.yml file in the Docker repo that does a blue-green deployment of sorts? Namely keep the old container until the last second and only kill it after the first one starts? Not sure how would that work with ports, admittedly.

Am I guessing properly that something like the following link should do it? Haven't tried anything yet, just probing for ideas at the moment.

I use the example docker-compose.yml file from the repo -- with tweaked IP, web password and volumes.

And here's my update script:

# Update pihole.
(pushd ~/pihole && docker-compose pull && docker-compose up --detach --remove-orphans --build pihole && popd)

# Delete non-needed Docker artifacts (containers, volumes, images, networks etc.).
(docker system prune -f)
(docker container prune -f)
(docker image prune -f)
(docker volume prune -f)
(docker buildx prune -f)

I keep it simple, two instances of Pi-Hole running each with there own IP address. I configure my DHCP server to issue both addresses to the network clients for their DNS servers. Then I can update and test one instance and the other instance staying running until I have tested that the new version is working well. Then I will update the second instance.

Are you talking about two physical servers? I'm looking for a solution with two Docker containers, of which one will be stopped after the other one gets upgraded.

Two docker containers on the same host. I use MacVlan docker network so I can define a IP address per container and they are fully isolated. It works for me. But if you found a solution that works for you that is great also.

Ah no, I haven't. That's why I am asking. If you have any tutorial or step-by-step guide on your setup I'd love to read it.

Here is one of my older posts where I used MacVlan to create pihole and DNSCrypt Proxy services. It may serve as a template for you. I have two directories in my /docker directory one called pihole1 and the other called pihole2. Each has it's own yaml and directory structure to support the two instances.

1 Like