Search code examples
dockerdocker-composedockerfilemicroservices

Is it possible to create a docker image whitout OS?


To install my microservice binaries I need a centos. And since I have 20 microservice I'm trying to find a way to optimize the images size so I'm wondering if there's a way to create a docker image without os and at the moment of deployment Docker takes the OS Layer from cache to put it in all the images.. I'm a beginner so I don't know if I'm clear in my statements ?


Solution

  • Yes, look at the scratch keyword (docs):

    You can use Docker’s reserved, minimal image, scratch, as a starting point for building containers.

    Also you may find useful using multi-stage builds.

    An example:

    FROM scratch
    ADD hello /
    
    FROM fedora
    RUN yum -y update && yum clean all
    RUN yum -y install nginx