1

Lets say we have a microservice which runs in docker container.

Now to bring up this service, it uses cache which is mounted on the host volume which gets shared by all the other docker images for same microservice. And to build this cache in app it takes 10 mins and then application gets ready to serve the request.

But this scenario gets failed when we will scale up and scale down, Lets say I am scaling up container will be available but its still not fully up because we need to wait to build the cache.

How you suggest to handle this scenario.

And at the font of this docker services we are planning to bring Nginx to load balance the request.

Thanks in Advance

bluecipher
  • 11
  • 1
  • So, you need to know when your docker microservice is fully up and running? Did I capture this right? – agentsmith Aug 28 '20 at 09:00
  • What's in the cache? Can you dynamically build it as you're using it, or build a fixed copy of it in the image? I'd try to improve the startup time dramatically and remove the dependency on shared storage, but that sounds like it could be a substantial redesign. – David Maze Aug 28 '20 at 14:58

1 Answers1

1

If I understand you right, you want to know when your container is fully up and running. One option could be the Health Check. This feature was added in Docker 1.12.

Description (from Docker Docs):

The health check will first run interval seconds after the container is started, and then again interval seconds after each previous check completes.

If a single run of the check takes longer than timeout seconds then the check is considered to have failed.

It takes retries consecutive failures of the health check for the container to be considered unhealthy. There you can specify to run any command to check your server status.

The Health of your container can be checked by using the inspect-command

docker inspect --format='{{json .State.Health}}' <container-id>

This feature adds also the "(healthy)"-information to the status in docker ps.

agentsmith
  • 1,226
  • 1
  • 14
  • 27
  • Not exactly, Container comes in healthy state after starting it, but its still building cache inside the container, And by the time it builds the cache we need to ensure the request should not hit to that new container when we will be scaling up the container. – bluecipher Aug 28 '20 at 09:32
  • Did you read the docs? You can specify *a command which is run inside your container periodically*. This can be used to check if your microservice has started. E. g. a `curl` to check if a server is reachable, `ping` or check for `lock-files` etc. And by checking the state (even this can be done from other containers, see [here](https://stackoverflow.com/questions/46916796/connect-to-docker-daemon-from-inside-docker-container)) you can tell if you service is ready or not. – agentsmith Aug 28 '20 at 10:01