Docker service update downtime

Viewed 155

I have an AWS EC2 with docker service. The service has just 1 container, and when I update the container (changing image), I have a downtime (about 1 minute).

This is my docker service create code:

docker service create \
    --name service-$IMAGE_NAME \
    --publish 80:80 \
    --env ENVIRONMENT=$(cat /etc/service_environment) \
    --env-file=/etc/.env \
    --replicas=1 \
    --update-failure-action rollback \
    --update-order start-first \
    $ECR_IMAGE

Here update code:

#pull image from private ECR repository
docker pull $IMAGE

docker service update \
--force \
--image $IMAGE:latest \
--update-failure-action rollback \
--update-order start-first \
service-$IMAGE_NAME

Why this happen? What's wrong? Thank you

1 Answers

Changing image means you are stopping existing docker instance, and start a new one. That's why it will be down for a while, in your case, 1 minute. It's the time for the docker instance to restart. You can make this seamless using 2 ec2 instance and load balancer. You update 1 instance and repointing the traffic to other instance, and then update the other one after the instance you've update is successful.

Related