I am creating and image to reuse in my projects which I want to push to Docker Hub.
I initially thought that I just had to make a folder, put a right Dockerfile with some additional files like configs and push it.
Then I realized that I also had to create an image based on this Dockerfile first.
So, I suppose, Docker Hub keeps the image that I created locally? Thus, images can be quite large, like gigabytes?
Please shed light on what's exactly is being pushed when I run docker push name/repo
.
A good start to understanding is checking out Docker's overview of images and containers.
In summary - Docker is built on a layered filesystem. Each command in a
Dockerfile
adds, writes or modifies files, which are stored as changes to the layer below. This process makes it easy to re-use base containers (because the layers are not modified) - and efficiently rebuild images when commands have not changed.And those filesystem layers (plus other metadata that make up an image) are what is pushed to Docker Hub.
A small Dockerfile often creates a much larger image, so why not upload just the Dockerfile? I think the reason is consistency. Often a Dockerfile starts with
FROM debian
orFROM alpine
or maybe with a version tag likeFROM python:3.5
. But when the image behind that tag changes, you will build different images from the same Dockerfile. At some point a build could break an application, or cause subtle bugs. But with all the filesystem layers cacged on Docker Hub, the same binary image runs every time.