dockeryamldocker-machinedocker-imagedocker-stack

Can I use/build custom created docker image to create another image?


I want to create an image A in one instance/server, but in that instance there is no internet connection.

So can I create an image B with all packages installed at my machine and then Push to x.x.x.x and use it in image A as the FROM tag?

It will look like :

FROM x.x.x.x/B:latest
RUN ***
ENTRYPOINT

Please suggest a correct solution for this problem.


Solution

  • Short answer - of course, you can. You can use any image, including your own, to build new images.

    Long answer - consider Docker multistage build for you purpose. This allows reduce the amount of images and the space occupied by your docker registry.

    You can read more on https://docs.docker.com/develop/develop-images/multistage-build/

    In short - you create a single Dockerfile where you define several images, based on each other. In case you don't need your base image outside from derived, this is your case. Following example will illustrate:

    Dockerfile

    # First create base image
    FROM foo:latest as mybase # note we tag it 'mybase' 
    RUN blahblah
    
    FROM mybase  # here we derive new image, note Dockerfile is same!
    RUN blahblahblah