Ever thought those Docker container images that anyone can use are magical, and thought about making one but don’t know how? Come along, I’ll teach you 😉
To start, you’ll need a Docker Hub account. That’s where all Docker container images live. Once you’ve got your account there, we can move to the command line and start using the Docker CLI.
Before we do anything, we need a project right? The project we’re going to use here is in this GitHub repo. It’s just a Python script that adds two numbers passed on the command line.
Now that we have a project let’s start with the login. Even though you don’t need to login to build your images, once you’re logged in you can forget it exists:

Now let’s build our image:

Here we used the -t parameter to name our image. After building we can check the image in our list of locally available images:

Now that we have an image ready, let’s tag it and check that it was tagged correctly:

This step is basically what lets us distribute our images. So after tagging your image, it’s time to push (send the image to Docker Hub):

And done. Now the image has been sent to Docker Hub, making it possible for anyone to use docker pull to download and use the image:

Something extra
Doing all these steps manually can get tiring if you need to push a lot of images, and beyond that, anything we do by hand can be prone to errors. So the natural path would be to automate these tasks.
There are several ways to do this, but let’s use a shell script I called push.sh for it:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In it I reproduced all the steps we did up to here, and to use it just do:

You can even put this script in a continuous delivery tool and let the magic happen.
Links
The code and steps demonstrated here are in this GitHub repo, go there and leave a ⭐️