Docker: one shared image or separate image for each service?

63 views Asked by At

I want to figure out the most efficient way (memory and space) to run multiple services with complicated dependencies.

Suppose, we have a project with 3 services:

  • service S1 only uses libraries A and B
  • service S2 only uses libraries B and C
  • service S3 only uses libraries A and C

So, if you create a separate image for each of these, you will end up with this structure:

  • S1
    • alpine layer
    • A and B libraries
  • S2
    • alpine layer
    • B and C libraries
  • S3
    • alpine layer
    • A and C libraries

Library layers do not share any files (though actually share libraries).

What is the best strategy to share the resources? Is it okay to use one image for all 3 services? (Store libraries A, B, C in one image layer)

Upd
We run all the services on one machine, not on a cluster
Upd 2
Here is an example (Spoiler: layers are not shared)

1

There are 1 answers

1
Tejas On

If you are following a mircroservice oriented architecture, then each service should have its own image. Docker images are cheap, but if you have 1 bulky image and use that in all the services, that would not be ideal.

Also, that way you wont have dependencies with other services if you want to upgrade service specific libraries.