Docker Community Forums

Share and learn in the Docker community.

Build once, Run anywhere concept


(Sanchezjjose) #1

How does build ONCE and run ANYWHERE concept work? For example for a node application, if I want to build an image, it will run ‘npm install’ to pull in dependencies, and now those dependencies live in the image until something changes and I need to pull in more images.

But when deploying or moving to a new environment, don’t I need to build the image or the container again? Meaning, isn’t it going to run ‘npm install’ again anyway?

I want to understand what is meant exactly by build once, run anywhere.

Thank you in advance.


(Ranjandas) #2

Hi,

When deploying or moving to a new environment you need not always rebuild (unless you want to update the image) the image. The Docker images are portable, you can use docker save to save the image as a tarball and ship it to any environment and load the image and run the container based on that image.

The Docker standard way of build once run anywhere is by using a global docker registry. eg Docker Hub, or an enterprise wide Docker Trusted Registry (DTR). In this method, the built image resides in the registry ,and you can run the container anywhere where you have access to these docker registries.

Regards


(Sanchezjjose) #3

Thank you this makes a lot of sense. I wasn’t familiar with the docker save command. That seems to be the missing piece. Thanks again!