Working with a public registry

After building an image we can push it to one of the mainstream public registries. For this example we have created an account with https://hub.docker.com/ with the username kjackal.

First we run the login command:

  1. docker login

Docker will ask for a Docker ID and password to complete the login.

  1. Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
  2. Username: kjackal
  3. Password: *******

Pushing to the registry requires that the image is tagged with your-hub-username/image-name:tag. We can either add proper tagging during build:

  1. docker build . -t kjackal/mynginx:public

Or tag an already existing image using the image ID. Obtain the ID by running:

  1. docker images

The ID is listed in the output:

  1. REPOSITORY TAG IMAGE ID SIZE
  2. mynginx local 1fe3d8f47868 16.1MB
  3. ....

Then use the tag command:

  1. docker tag 1fe3d8f47868 kjackal/mynginx:public

Now that the image is tagged correctly, it can be pushed to the registry:

  1. docker push kjackal/mynginx

At this point we are ready to microk8s kubectl apply -f a deployment with our image:

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: nginx-deployment
  5. labels:
  6. app: nginx
  7. spec:
  8. selector:
  9. matchLabels:
  10. app: nginx
  11. template:
  12. metadata:
  13. labels:
  14. app: nginx
  15. spec:
  16. containers:
  17. - name: nginx
  18. image: kjackal/mynginx:public
  19. ports:
  20. - containerPort: 80

We refer to the image as image: kjackal/mynginx:public. Kubernetes will search for the image in its default registry, docker.io.

Last updated 1 year, 2 months ago. Help improve this document in the forum.