# Cannot push Docker image to Docker Hub from Okteto Deployment Job

**URL:** <https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876>\
**Category:** Help\
**Created:** [June 13, 2023, 2:33am UTC](https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876 "2023-06-13T02:33:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cardigan7240](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cardigan7240](https://community.okteto.com/u/Cardigan7240)\
**Post date:** [June 13, 2023, 2:33am UTC](https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876/1 "2023-06-13T02:33:44Z")

</div>

Hi

I did a small **Java** project, which is on **[Github](https://github.com/foundationer/ideal-octo-tribble)**.

I managed to package it with **Maven** , build a **Docker** image and publish it to Docker Hub using **Github** actions. Now I would like to deploy it to an **Okteto** environment.

However, when the Okteto deployment job runs, I get this error:

```auto
#13 ERROR: server message: insufficient_scope: authorization failed
------
 > exporting to image:
------
error building service 'ideal-octo-tribble': error building image 'foundationer/ideal-octo-tribble:main': You are not authorized to push image 'foundationer/ideal-octo-tribble:main'
 x Error building service 'ideal-octo-tribble': error building image 'foundationer/ideal-octo-tribble:main': You are not authorized to push image 'foundationer/ideal-octo-tribble:main'
deploy command failed: exit status 1

```

I don’t understand why this happens. I set the Docker Hub user and token as secrets, both in Github and Okteto. In Github it works fine, but in Okteto it doesn’t.

Also, why it attempts to build the image from scratch instead of downloading it from Docker Hub? I already pushed it to my repo using Github.

This is my first time using Okteto, by the way, so sorry if these questions are too basic.  
I would greatly appreciate your help.

---

<div class="post-metadata">

**Author:** ![AgustinRamiroDiaz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/agustinramirodiaz/32/34_2.png) [@AgustinRamiroDiaz](https://community.okteto.com/u/AgustinRamiroDiaz)\
**Post date:** [June 14, 2023, 6:41pm UTC](https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876/2 "2023-06-14T18:41:35Z")

</div>

Hi @Cardigan7240 and welcome!

This is mostly sure a problem with authentication to dockerhub

Can you explain a bit more what your current setup is? When you say “However, when the Okteto deployment job runs, I get this error:” do you mean you are running `okteto deploy` locally, or in a github action? Are you using an okteto’s official github action like [this one](https://github.com/marketplace/actions/deploy-preview-environment)?

Also, are you using [cloud.okteto.com](http://cloud.okteto.com)? or a private cluster?

> Also, why it attempts to build the image from scratch instead of downloading it from Docker Hub? I already pushed it to my repo using Github.

The `okteto.yml` manifest and the setup would help us understand why. It’s probably a configuration issue, but you’ll likely hit the same auth problems when trying to pull

---

<div class="post-metadata">

**Author:** ![Cardigan7240](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cardigan7240](https://community.okteto.com/u/Cardigan7240)\
**Post date:** [June 14, 2023, 10:03pm UTC](https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876/3 "2023-06-14T22:03:59Z")

</div>

Hi **Agustín**

Thanks for reaching out. Let me answer your questions.

I ran the deploy from the **Okteto Cloud UI** , by clicking on “Launch Dev Environment” and selecting the **Github** repo. I didn’t use the Github action you mentioned… I should give it a try.

Here are the contents of the okteto.yml file:

```auto

build:
  ideal-octo-tribble:
    image: foundationer/ideal-octo-tribble:main
    context: .
deploy:
  - kubectl apply -f k8s.yml
dev:
  ideal-octo-tribble:
    image: okteto/maven:3
    command: bash
    sync:
      - .:/usr/src/app
    forward:
      - 5005:5005
    volumes:
      - /root/.m2

```

Thanks.

---

<div class="post-metadata">

**Author:** ![AgustinRamiroDiaz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/agustinramirodiaz/32/34_2.png) [@AgustinRamiroDiaz](https://community.okteto.com/u/AgustinRamiroDiaz)\
**Post date:** [June 15, 2023, 8:30pm UTC](https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876/4 "2023-06-15T20:30:28Z")

</div>

@Cardigan7240 thanks for providing your manifest and answering my questions!

The manifest you provided is trying to build and push the image `foundationer/ideal-octo-tribble:main`

My recommendation while using okteto is to push your images to [okteto’s registry](https://www.okteto.com/docs/cloud/registry/). You’ll be able to use these images in your namespace.

For that, your manifest should change to something like

```auto
build:
  ideal-octo-tribble:
    image: okteto.dev/ideal-octo-tribble:main
    context: .
deploy:
  - kubectl apply -f k8s.yml
dev:
  ideal-octo-tribble:
    image: okteto/maven:3
    command: bash
    sync:
      - .:/usr/src/app
    forward:
      - 5005:5005
    volumes:
      - /root/.m2

```

and also replace in your k8s.yml the ocurrences of `foundationer/ideal-octo-tribble:main` by `okteto.dev/ideal-octo-tribble:main` (in the case that doesn’t work, try with `registry.cloud.okteto.net/<your namespace>/foundationer/ideal-octo-tribble:main`)

This should fix your issue 😃

---

<div class="post-metadata">

**Author:** ![Cardigan7240](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cardigan7240](https://community.okteto.com/u/Cardigan7240)\
**Post date:** [June 16, 2023, 2:53am UTC](https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876/5 "2023-06-16T02:53:35Z")

</div>

Hey **Agustín**

I did what you showed me, but now I get a different error:

`Error building service 'ideal-octo-tribble': error building image 'registry.cloud.okteto.net/dev-previews-ideal-octo-tribble-foundationer/ideal-octo-tribble:1.0.0': build failed: failed to solve: error writing layer blob: content digest sha256:d1669123f28121211977ed38e663dca1a397c0c001e5386598b96c89b1b1cd51: not found`

I tried to do the deploy both from the **Okteto Cloud UI** and using the **Github** action you showed me. I got the same error with both deployment methods.

---

<div class="post-metadata">

**Author:** ![jona](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/jona/32/353_2.png) [@jona](https://community.okteto.com/u/jona)\
**Post date:** [June 16, 2023, 8:15pm UTC](https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876/6 "2023-06-16T20:15:22Z")

</div>

Hello @Cardigan7240 ,

There might be an issue with your cache, so I am curious if you are able to build using the Okteto CLI instead of building through the UI, so that you can get around the cache and potentially get around this issue. You just need to run your build with the command `okteto build <your service> --no-cache`, and you can find more info here: [Okteto CLI | Okteto Documentation](https://www.okteto.com/docs/reference/cli/#build)

Let us know if that helped!  
-Jona

---

<div class="post-metadata">

**Author:** ![Cardigan7240](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cardigan7240](https://community.okteto.com/u/Cardigan7240)\
**Post date:** [June 18, 2023, 2:36am UTC](https://community.okteto.com/t/cannot-push-docker-image-to-docker-hub-from-okteto-deployment-job/876/7 "2023-06-18T02:36:28Z")

</div>

Hi **Jona**

That solved the issue. I built the project from the CLI using the --no-cache option. It finished without errors. Then I went to the UI, spun up the environment and started right away.

Thanks a lot to everyone for your help!
