# How to use a public registry

**URL:** <https://discuss.kubernetes.io/t/how-to-use-a-public-registry/11271>\
**Category:** microk8s\
**Tags:** docs\
**Created:** [June 4, 2020, 3:20pm UTC](https://discuss.kubernetes.io/t/how-to-use-a-public-registry/11271 "2020-06-04T15:20:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![evilnick](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/evilnick/32/3481_2.png) [@evilnick](https://discuss.kubernetes.io/u/evilnick)\
**Post date:** [June 4, 2020, 3:20pm UTC](https://discuss.kubernetes.io/t/how-to-use-a-public-registry/11271/1 "2020-06-04T15:20:32Z")

</div>

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/](https://hub.docker.com/) with the username `kjackal`.

First we run the login command:

```bash
docker login

```

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

```auto
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.
Username: kjackal
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:

```bash
docker build . -t kjackal/mynginx:public

```

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

```bash
docker images

```

The ID is listed in the output:

```auto
REPOSITORY TAG IMAGE ID SIZE
mynginx local 1fe3d8f47868 16.1MB
....

```

Then use the `tag` command:

```bash
docker tag 1fe3d8f47868 kjackal/mynginx:public

```

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

```bash
docker push kjackal/mynginx

```

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

```auto
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: kjackal/mynginx:public
        ports:
        - containerPort: 80

```

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

---

<div class="post-metadata">

**Author:** ![Ashutosh\_Gautam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/ashutosh_gautam/32/13284_2.png) [@Ashutosh\_Gautam](https://discuss.kubernetes.io/u/Ashutosh_Gautam)\
**Post date:** [September 13, 2023, 8:49pm UTC](https://discuss.kubernetes.io/t/how-to-use-a-public-registry/11271/2 "2023-09-13T20:49:47Z")

</div>

There seems to be a functional bug in here:  
When we are tagging an existing docker image we use: docker tag 1fe3d8f47868 kjackal/mynginx:public  
But while pushing that image we use: docker push kjackal/mynginx

So now according to docker basics if we do not provide any tag to the image it will append latest as a tag so this command will through an error.

to remove this issue we can use any one method from below:

1. change push command to → docker push kjackal/mynginx:public
2. change tag command to → docker tag 1fe3d8f47868 kjackal/mynginx:latest
