Blog describing pushing a container image using MiniKube.
MiniKube actually has a copy of Docker executable in it.
We will be using that copy to login to Docker Hub and push our container image.
Assumptions
- You have MiniKube installed and running.
If not, you can refer to this blog post Setup and running a local Kubernetes cluster on Windows 11 using Minikube and this post Setup external virtual switch for Hyper-V for use with Minikube - You have a container image
If not, you can refer to this blog post Containerized a ASP.NET Core MVC Application and running it in MiniKube (Kubernetes) using command-line interface (CLI) to create one. - You have PowerShell Core installed
- You know how to run a PowerShell Core session as administrator
- You have a Docker Hub account and repository
Steps
- SSH to MiniKube
- Re-tag our image
- Log in to Docker Hub
- Push container image to Docker Hub
SSH to MiniKube
To login to MiniKube, execute the following command:
minikube ssh
After the command finished executing, you should see an output like the below:
Re-tag our image
To push our local container image to Docker hub, we need to re-tag the container image from<image-name>:<tag>
into the format of <docker-hub-username>/<image-name>:<tag>
Before that, let’s take a look at the images that are available by running this command:
docker image ls
The container that we want to push to Docker Hub is “basic-mvc
“.
My Docker Hub username is zhixian
So I want to re-tag my local image to zhixian/basic:mvc:1
To do so, execute the command:
docker tag basic-mvc:1 zhixian/basic-mvc:1
After I finished executing the command and re-examine the images, I would see that I have an image tagged as zhixian/basic-mvc:1
Note that the image ID is the same as basic-mvc:1
docker login
To push this image, we need to login to our Docker Hub account by running the following command in MiniKube SSH:
docker login
The command will prompt you for enter your Docker Hub username and password.
The following screenshot is what you should be seeing when you successfully log in.
Push container image to Docker Hub
To push the image to Docker Hub, run the commanddocker push <docker-hub-username>/<image-name>:<tag>
.
So in my case, the command would look like:
docker push zhixian/basic-mvc:1
Aside: Pushing the image may take a long time. Not sure if its because I’m using the free tier or its due to MiniKube. 🤔
After the command finished, you should be able to see it in your Docker Hub.
Leave a comment