In February I wrote about deploying Portainer git stacks through Portainer's API. Since October none of my stacks deploy that way. Each stack is plain Docker Compose in a folder on the server, deployed over SSH:

  1. A push to main makes CI build an image tagged with the commit and check that it boots.
  2. The deploy script copies the compose file to the server, sets the new tag in the .env there (keeping the previous one), and runs docker rollout on the web service.
  3. docker rollout starts a new container beside the old one. Traefik routes to it once its health check passes, and the old one is drained and removed.
  4. The script checks the version on the health endpoint and runs smoke tests. A failure rolls the previous image back out.

I left Portainer for the rollout. Its redeploy recreates the containers, so every deploy had a gap. A rollout has none, and a build that never becomes healthy leaves the old container serving.

Draining needed more care than I expected. I measured hung requests during rolls on two sites: with no drain, 3 of 311 requests hung in a roll; with a fixed 8-second wait, 2 of 289, because Traefik sometimes kept routing to the old container for longer than that. What worked was a drain hook that makes the health endpoint return 503 and then waits until no request has arrived for 3 seconds: 0 of 1,946 across eight rolls.

Databases, and services that publish host ports, still run as a single container and restart with docker compose up -d.