V
V
Vasily Medvedev2020-09-25 11:09:30
Software Deployment
Vasily Medvedev, 2020-09-25 11:09:30

How to deploy a docker container without downtime?

What we have:
2 docker containers: app (node.js) and nginx (reverse-proxy)

Requirement:
Have a minimal service downtime.
Some queries may take a long time to complete. It is important to return the response to the request that came before the deployment.

The essence of the problem:
When updating the project (docker-compose build && docker-compose up -d), we have a simple 5-10sec. (start time of node.js in app container).

As I imagine the solution:
1. Using the Green / Blue pattern. Couldn't find a simple solution (without crutches)
2. Docker Swarm Stack

Tell me the simplest possible approach to deployment with zero downtime (in the absence of DevOps'a).

docker-compose.yml

version: '3.3'

services:

  app:
    build:
      context: .
    restart: unless-stopped
    env_file: .env

  nginx:
    build: ./docker/nginx
    restart: unless-stopped
    depends_on:
      - app
    ports:
      - ${APP_PORT}:80
    volumes:
      - ./static:/var/www:cached

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Karasik, 2020-09-25
@vitaly_il1

How I imagine the solution:

Generally correct. The idea is simple - raise a new instance, stop sending traffic to the old one, wait until the request processing is over, kill the old one. This is not fantastically difficult, but it must be implemented.
Or use the orchestrator - K8S, etc.
Another option - a little more expensive, but more reliable - is to use a managed service - AWS Elastic Beanstalk, Google App Engine , Heroku.

Z
zohan1993, 2020-09-25
@zohan1993

Initialize Docker Swarm with one node.
Create a service with an application - app.
And update the service with the necessary parameters to eliminate downtime.
Simple example:

docker service create --name nginx --replicas 1 --publish 80:80 nginx:1.18
docker service update nginx --update-order start-first --image nginx:1.19

docker service update

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question