Unable to use base image in okteto (requires authorization)

I have a base image in the root of my project, which all other images depend on. These images are trying to accept an arg and source that image from the arg.

I get an error in okteto that authorization is required.

example paraphrased okteto.yml

build:
  dev:
    context: .
    dockerfile: ./Dockerfile
    args:
      AM_URL: $AM_URL
      API_URL: $API_URL
      DEBUGGER_OFF: $DEBUGGER-OFF
      REALM_PATH: $REALM_PATH
      JOURNEY_LOGIN: $JOURNEY_LOGIN
      JOURNEY_REGISTER: $JOURNEY_REGISTER
      WEB_OAUTH_CLIENT: $WEB_OAUTH_CLIENT
      REST_OAUTH_CLIENT: $REST_OAUTH_CLIENT
      REST_OAUTH_SECRET: $REST_OAUTH_SECRET

  reactjs-todo:
    context: .
    dockerfile: samples/reactjs-todo/Dockerfile
    depends_on: dev
    args:
      SOURCE_IMAGE: ${OKTETO_BUILD_DEV_IMAGE}

docker-compose.yml paraphrased

services:
  reactjs-todo:
    container_name: reactjs-todo
    build:
      context: ./
      dockerfile: ./samples/reactjs-todo/Dockerfile
      args:
        SOURCE_IMAGE: $SOURCE_IMAGE
        AM_URL: $AM_URL
        DEBUGGER_OFF: $DEBUGGER-OFF
        REALM_PATH: $REALM_PATH
        API_URL: $API_URL
        JOURNEY_LOGIN: $JOURNEY_LOGIN
        JOURNEY_REGISTER: $JOURNEY_REGISTER
        WEB_OAUTH_CLIENT: $WEB_OAUTH_CLIENT
    ports:
      - '8443:80'
    restart: on-failure

example Dockerfile for given service

ARG SOURCE_IMAGE=$SOURCE_IMAGE

FROM $SOURCE_IMAGE as builder
WORKDIR /app/builder

RUN npx nx build reactjs-todo --prod 

FROM nginx:1.19.2
...rest of docker file

This is shortened as there are a few more services here but I think this is all the provided information needed for this. I didn’t want to overload this post.

If there is a better way to ensure that my images are using this base image, i’m happy to change, i just was unable to get it working.

I understand okteto.dev/namespace:tag gets parsed from that to the actual image in the okteto registry but i figured it was easier to just pass it in from the okteto.yml?

The error i get is that

You are not authorized to push image ...

Hello :wave: I tried to duplicate the setup, only it’s simplified to what I think you’re trying to accomplish. I used a fork of the go-getting-started repo, GitHub - jmacelroy/go-getting-started: Develop Go Apps in Kubernetes with Okteto

I modified it so that there is a sub-directory called test with a Dockerfile that expects the image from the one in the root directory to be the base.

Base Image from root Dockerfile

FROM golang:buster

WORKDIR /app
ADD . .
RUN go build -o /usr/local/bin/hello-world

EXPOSE 8080
CMD ["/usr/local/bin/hello-world"]

The image that is going to use the base image in ./test

ARG SOURCE_IMAGE=$SOURCE_IMAGE

FROM $SOURCE_IMAGE as builder


CMD ["/bin/bash"]

I then run okteto deploy --build and it all works. I’m wondering if you need to force the build and there’s a caching issue?

➜  go-getting-started git:(master) ✗ okteto deploy --build
 i  Using jmacelroy @ okteto.assessment.jdm.okteto.net as context
 i  Building 'Dockerfile' in tcp://buildkit.assessment.jdm.okteto.net:443...
[+] Building 28.9s (9/9) FINISHED
 => [internal] load .dockerignore                                                                                                                                                                                                                                            0.1s
 => => transferring context: 2B                                                                                                                                                                                                                                              0.1s
 => [internal] load build definition from buildkit-1563700302                                                                                                                                                                                                                0.1s
 => => transferring dockerfile: 180B                                                                                                                                                                                                                                         0.1s
 => [internal] load metadata for docker.io/library/golang:buster                                                                                                                                                                                                             0.8s
 => [1/4] FROM docker.io/library/golang:buster@sha256:fc1e0b02674cef154ceca0ba6ca4d3658bd385d5faadecbbd44809727a56329d                                                                                                                                                       0.0s
 => => resolve docker.io/library/golang:buster@sha256:fc1e0b02674cef154ceca0ba6ca4d3658bd385d5faadecbbd44809727a56329d                                                                                                                                                       0.0s
 => [internal] load build context                                                                                                                                                                                                                                            0.2s
 => => transferring context: 3.46kB                                                                                                                                                                                                                                          0.2s
 => CACHED [2/4] WORKDIR /app                                                                                                                                                                                                                                                0.0s
 => [3/4] ADD . .                                                                                                                                                                                                                                                            0.0s
 => [4/4] RUN go build -o /usr/local/bin/hello-world                                                                                                                                                                                                                        12.8s
 => exporting to image                                                                                                                                                                                                                                                      15.0s
 => => exporting layers                                                                                                                                                                                                                                                     13.1s
 => => exporting manifest sha256:c18b6b3056efe92dccb973d42720fb734a0b6ca34395dbd20ed61537fbd3f0fc                                                                                                                                                                            0.0s
 => => exporting config sha256:25232fe2af7737a7fb2af67ce16ef84c42e859769cae407a18d45906cfc2ea08                                                                                                                                                                              0.0s
 => => pushing layers                                                                                                                                                                                                                                                        1.7s
 => => pushing manifest for registry.assessment.jdm.okteto.net/jmacelroy/go-getting-started-dev:okteto@sha256:c18b6b3056efe92dccb973d42720fb734a0b6ca34395dbd20ed61537fbd3f0fc                                                                                               0.2s
 ✓  Image 'registry.assessment.jdm.okteto.net/jmacelroy/go-getting-started-dev:okteto' successfully pushed
 !  Build 'go-getting-started': Dockerfile './test/Dockerfile' is not in a relative path to context './test'
 i  Building './test/Dockerfile' in tcp://buildkit.assessment.jdm.okteto.net:443...
[+] Building 1.6s (5/5) FINISHED
 => [internal] load build definition from buildkit-528025309                                                                                                                                                                                                                 0.1s
 => => transferring dockerfile: 127B                                                                                                                                                                                                                                         0.1s
 => [internal] load .dockerignore                                                                                                                                                                                                                                            0.1s
 => => transferring context: 2B                                                                                                                                                                                                                                              0.1s
 => [internal] load metadata for registry.assessment.jdm.okteto.net/jmacelroy/go-getting-started-dev@sha256:c18b6b3056efe92dccb973d42720fb734a0b6ca34395dbd20ed61537fbd3f0fc                                                                                                 0.2s
 => [1/1] FROM registry.assessment.jdm.okteto.net/jmacelroy/go-getting-started-dev@sha256:c18b6b3056efe92dccb973d42720fb734a0b6ca34395dbd20ed61537fbd3f0fc                                                                                                                   0.0s
 => => resolve registry.assessment.jdm.okteto.net/jmacelroy/go-getting-started-dev@sha256:c18b6b3056efe92dccb973d42720fb734a0b6ca34395dbd20ed61537fbd3f0fc                                                                                                                   0.0s
 => exporting to image                                                                                                                                                                                                                                                       1.2s
 => => exporting layers                                                                                                                                                                                                                                                      0.0s
 => => exporting manifest sha256:54bc58be1cddcafba379a5bc3a582dabcdcdf60c01e790b1c144586943a12c63                                                                                                                                                                            0.0s
 => => exporting config sha256:1d09ef8235cecee9a5cd268e4c1dc5fdf1fc7ea3b43b3da46c4b8784ac32716d                                                                                                                                                                              0.0s
 => => pushing layers                                                                                                                                                                                                                                                        0.9s
 => => pushing manifest for registry.assessment.jdm.okteto.net/jmacelroy/go-getting-started-go-getting-started:okteto@sha256:54bc58be1cddcafba379a5bc3a582dabcdcdf60c01e790b1c144586943a12c63                                                                                0.3s
 ✓  Image 'registry.assessment.jdm.okteto.net/jmacelroy/go-getting-started-go-getting-started:okteto' successfully pushed
 i  Running 'kubectl apply -f k8s.yml'
deployment.apps/hello-world configured
service/hello-world configured
 i  Endpoints available:
  - https://hello-world-jmacelroy.assessment.jdm.okteto.net/
  - https://hello-world-jmacelroy.assessment.jdm.okteto.net/
 ✓  Development environment 'go-getting-started' successfully deployed
 i  Run 'okteto up' to activate your development container

My Okteto manifest is…


name: go-getting-started

build:
  dev:
    context: .
    dockerfile: Dockerfile

  go-getting-started:
    context: ./test
    dockerfile: ./test/Dockerfile
    depends_on: dev
    args:
      SOURCE_IMAGE: ${OKTETO_BUILD_DEV_IMAGE}

# The deploy section defines how to deploy your development environment
# More info: https://www.okteto.com/docs/reference/manifest/#deploy
deploy:
  - kubectl apply -f k8s.yml

Is there something different in our setups? Are you setup with the proper namespaces? What are the image names that it’s saying you can’t access?

The main difference is I am using a compose file and a okteto.yml, maybe i dont need boht but its how ive always had it setup.

Oh, I missed that part in my first reading of your issue. I think it’s possible that may have something to do with it. I don’t believe the compose file should be playing a part, but it seems plausible there’s an issue. Essentially though I think you have build instructions in two places and it may be triggering a defect or just a usability bug. I’m going to share with the team on Monday and will also attempt further to reproduce it a bit.

I wonder if okteto build works in the absence of the compose file? If so, I do think the fastest resolution may be to just have an okteto manifest as I’m not sure the compose file will work in this case if just using it with local compose. I don’t know that it would know how SOURCE_IMAGE would easily get set if just running local compose with that file and it may be a simplification to use just the okteto manifest. It may be worth trying that out to get unblocked while on our side we work on figuring out the issue with the original attempt.

In my case i’d have to write a different deploy script for the okteto.yml.

The key thing here is that I just want to source the base image as the stage for various other services. I was trying to figure out how to get the okteto.dev/image:tag to work but i couldn’t figure out what that was supposed to be in my case.

So i figured the easiest way was to build the base image as a service in my okteto.yml, all other services use a depends_on: dev so that gets built first, and I use the okteto variable as an argument in the image for the stage.

Using the example Jacob created (GitHub - jmacelroy/go-getting-started: Develop Go Apps in Kubernetes with Okteto) and adding a compose I am not able to reproduce your scenario. This is the compose I added.

services:
  go-getting-started:
    container_name: go-getting-started
    build:
      context: ./
      dockerfile: ./test/Dockerfile
      args:
        SOURCE_IMAGE: $SOURCE_IMAGE
        AM_URL: $AM_URL
        DEBUGGER_OFF: $DEBUGGER-OFF
        REALM_PATH: $REALM_PATH
        API_URL: $API_URL
        JOURNEY_LOGIN: $JOURNEY_LOGIN
        JOURNEY_REGISTER: $JOURNEY_REGISTER
        WEB_OAUTH_CLIENT: $WEB_OAUTH_CLIENT
    ports:
      - '8443:80'
    restart: on-failure

If you want to make sure that your images use a base image, in this scenario, just run okteto build. This command will use your okteto.yml by default. On the other hand, I see that your okteto.yml has no deploy section so if you want to deploy your environment you should run okteto deploy -f docker-compose.yml previously having built your images with okteto build. It seems that your build using the manifest does not work. Can you check that the repo given as an example + including the compose file fits your scenario?

I shortened all my files for the purposes of sharing here. I do have a deploy section. it is like so

deploy:
  compose:
    file: docker-compose.yml

(This above seems to be the main difference between the examples). I am not sure if this just outright changes everything but its possible i’m not very experienced in docker/kubernetes.

When running in okteto, my dev base image builds fine. When building the next service I will get an error like this:

#3 [internal] load metadata for docker.io/library/base:latest
#3 ERROR: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
#4 [internal] load metadata for docker.io/library/nginx:1.21.6
#4 CANCELED------> [internal] load metadata for docker.io/library/base:latest:
------error building service 'angular-todo': 
error building image 'registry.cloud.okteto.net/pr-323-ryanbas21/forgerock-javascript-sdk-angular-todo:okteto': 
You are not authorized to push image 'pr-323-ryanbas21/forgerock-javascript-sdk-angular-todo:okteto'
x Error building service 'angular-todo': error building image 'registry.cloud.okteto.net/pr-323-ryanbas21/forgerock-javascript-sdk-angular-todo:okteto': 
You are not authorized to push image 'pr-323-ryanbas21/forgerock-javascript-sdk-angular-todo:okteto'

(sorry for formatting tried to make it prettier).

Basically my interpretation is that i get an authorization error because its trying to pull an image that just doesn’t exist which is probably because the arg variable is blank somehow. I assume, this is somehow a missing link between mysetup passing the arg in okteto.yml vs docker-compose.yml (which i am also passing it in)

Running my branch locally produces the same outputs

 ~/programming/forgerock-javascript-sdk  on update-docker *23  okteto build                                                                                                   ok
 !  $AM_URL secret is being overridden by a local environment variable by the same name.
 !  $API_URL secret is being overridden by a local environment variable by the same name.
 !  $CENTRAL_LOGIN_CLIENT secret is being overridden by a local environment variable by the same name.
 !  $REST_OAUTH_CLIENT secret is being overridden by a local environment variable by the same name.
 !  $REST_OAUTH_SECRET secret is being overridden by a local environment variable by the same name.
 !  $SCOPE secret is being overridden by a local environment variable by the same name.
 !  $TIMEOUT secret is being overridden by a local environment variable by the same name.
 !  $WEB_OAUTH_CLIENT secret is being overridden by a local environment variable by the same name.
 i  Building 'Dockerfile' in tcp://buildkit.cloud.okteto.net:443...
[+] Building 140.8s (9/9) FINISHED
 => [internal] load .dockerignore                                                                                                                                            0.5s
 => => transferring context: 178B                                                                                                                                            0.3s
 => [internal] load build definition from buildkit-2369565495                                                                                                                0.4s
 => => transferring dockerfile: 1.08kB                                                                                                                                       0.3s
 => [internal] load metadata for docker.io/library/node:16.17.0                                                                                                              0.6s
 => [1/4] FROM docker.io/library/node:16.17.0@sha256:a5d9200d3b8c17f0f3d7717034a9c215015b7aae70cb2a9d5e5dae7ff8aa6ca8                                                        0.1s
 => => resolve docker.io/library/node:16.17.0@sha256:a5d9200d3b8c17f0f3d7717034a9c215015b7aae70cb2a9d5e5dae7ff8aa6ca8                                                        0.1s
 => [internal] load build context                                                                                                                                           10.8s
 => => transferring context: 12.58MB                                                                                                                                        10.7s
 => CACHED [2/4] WORKDIR /app/builder                                                                                                                                        0.0s
 => [3/4] COPY . /app/builder/                                                                                                                                               0.8s
 => [4/4] RUN npm install                                                                                                                                                   82.2s
 => exporting to image                                                                                                                                                      45.2s
 => => exporting layers                                                                                                                                                     36.3s
 => => exporting manifest sha256:cbb4f9bac595412f13947dd7c426aa95df701c15e731cc830de0a936a63bb54a                                                                            0.0s
 => => exporting config sha256:139efbdf75fb617e9760306bc4068d8711de64bc5b52c9b2bc1baf80efb4f669                                                                              0.0s
 => => pushing layers                                                                                                                                                        7.6s
 => => pushing manifest for registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-dev:okteto@sha256:cbb4f9bac595412f13947dd7c426aa95df701c15e731cc830de0a936a63bb54a  1.3s
 ✓  Image 'registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-dev:okteto' successfully pushed
 i  Building 'samples/angular-todo/Dockerfile' in tcp://buildkit.cloud.okteto.net:443...
[+] Building 1.4s (4/4) FINISHED
 => [internal] load build definition from buildkit-1912522520                                                                                                                0.9s
 => => transferring dockerfile: 309B                                                                                                                                         0.2s
 => [internal] load .dockerignore                                                                                                                                            0.8s
 => => transferring context: 178B                                                                                                                                            0.1s
 => ERROR [internal] load metadata for docker.io/library/base:latest                                                                                                         0.2s
 => CANCELED [internal] load metadata for docker.io/library/nginx:1.21.6                                                                                                     0.3s
------
 > [internal] load metadata for docker.io/library/base:latest:
------
 x  Error building service 'angular-todo': error building image 'registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-angular-todo:okteto': You are not authorized to push image 'ryanbas21/forgerock-javascript-sdk-angular-todo:okteto'

I have been able to reproduce a similar behavior if the image that makes use of the base requires a private image for its build. Can you prove that your image that depends on the base image can be built independently?

That dev service is what i want my base image to be, so its built.

here is the okteto.yml for those two services.

# The build section defines how to build the images of your development environment
# More info: https://www.okteto.com/docs/reference/manifest/#build
build:
  dev:
    context: .
    dockerfile: ./Dockerfile
    args:
      AM_URL: $AM_URL
      API_URL: $API_URL
      DEBUGGER_OFF: $DEBUGGER-OFF
      REALM_PATH: $REALM_PATH
      JOURNEY_LOGIN: $JOURNEY_LOGIN
      JOURNEY_REGISTER: $JOURNEY_REGISTER
      WEB_OAUTH_CLIENT: $WEB_OAUTH_CLIENT
      REST_OAUTH_CLIENT: $REST_OAUTH_CLIENT
      REST_OAUTH_SECRET: $REST_OAUTH_SECRET

  # You can use the following env vars to refer to this image in your deploy commands:
  #  - OKTETO_BUILD_ANGULAR-TODO_REGISTRY: image registry
  #  - OKTETO_BUILD_ANGULAR-TODO_REPOSITORY: image repo
  #  - OKTETO_BUILD_ANGULAR-TODO_IMAGE: image name
  #  - OKTETO_BUILD_ANGULAR-TODO_TAG: image tag
  angular-todo:
    context: .
    dockerfile: samples/angular-todo/Dockerfile
    args:
      AM_URL: $AM_URL
      API_URL: $API_URL
      DEBUGGER_OFF: $DEBUGGER-OFF
      REALM_PATH: $REALM_PATH
      JOURNEY_LOGIN: $JOURNEY_LOGIN
      JOURNEY_REGISTER: $JOURNEY_REGISTER
      WEB_OAUTH_CLIENT: $WEB_OAUTH_CLIENT
      REST_OAUTH_CLIENT: $REST_OAUTH_CLIENT
      REST_OAUTH_SECRET: $REST_OAUTH_SECRET

sorry, maybe I expressed myself wrongly. What I mean is that the service angular-todo seems to have a dependency on an image that you don’t have access to. I don’t mean dev but another one that you later use during its construction. For example, your secondary image has more FROM... instructions than the one using dev? That is how I was able to reproduce your scenario at least with the information you have given.

i’m hoping its not me doing something dumb

I think nginx/1.21.6 is no longer accessible, that’s why you have this error.

Just tried with nginx:1.22.1-alpine

 ✓  Image 'registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-dev:okteto' successfully pushed
 i  Building 'samples/angular-todo/Dockerfile' in tcp://buildkit.cloud.okteto.net:443...
[+] Building 1.0s (4/4) FINISHED
 => [internal] load build definition from buildkit-86541082                                                                                                                  0.4s
 => => transferring dockerfile: 314B                                                                                                                                         0.3s
 => [internal] load .dockerignore                                                                                                                                            0.5s
 => => transferring context: 178B                                                                                                                                            0.3s
 => ERROR [internal] load metadata for docker.io/library/base:latest                                                                                                         0.5s
 => CANCELED [internal] load metadata for docker.io/library/nginx:1.22.1-alpine                                                                                              0.5s
------
 > [internal] load metadata for docker.io/library/base:latest:
------
 x  Error building service 'angular-todo': error building image 'registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-angular-todo:okteto': You are not authorized to push image 'ryanbas21/forgerock-javascript-sdk-angular-todo:okteto'

im trying some of the newer nginx images, although feels weird that even that release would be not avaiilable.

Ok, you were correct. I was able to get it working with the most recent images.

Thanks and im sorry for taking you down this road, i assumed it was me with the image variable! so so sorry

great! We are here to help :slight_smile:

I lied, I thought it was working but even on nginx:latest its failing.

Is this an nginx thing or okteto thing?

 => => pushing manifest for registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-dev:okteto@sha256:3f0765473818e66d48fb8f09839d175028ed3787e38cf6b61ddbcface7014e1c  0.7s
 ✓  Image 'registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-dev:okteto' successfully pushed
 i  Building 'samples/reactjs-todo/Dockerfile' in tcp://buildkit.cloud.okteto.net:443...
[+] Building 0.8s (4/4) FINISHED
 => [internal] load build definition from buildkit-857666209                                                                                                                 0.2s
 => => transferring dockerfile: 358B                                                                                                                                         0.1s
 => [internal] load .dockerignore                                                                                                                                            0.2s
 => => transferring context: 178B                                                                                                                                            0.1s
 => ERROR [internal] load metadata for docker.io/library/base:latest                                                                                                         0.4s
 => CANCELED [internal] load metadata for docker.io/library/nginx:latest                                                                                                     0.4s
------
 > [internal] load metadata for docker.io/library/base:latest:
------
 x  Error building service 'reactjs-todo': error building image 'registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-reactjs-todo:okteto': You are not authorized to push image 'ryanbas21/forgerock-javascript-sdk-reactjs-todo:okteto'

if its not an okteto thing i can keep debugging

ok, can you share the output by running okteto build --progress=plain ?

#9 DONE 0.7s
✓ Image ‘registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-dev:okteto’ successfully pushed
i Building ‘samples/angular-todo/Dockerfile’ in tcp://buildkit.cloud.okteto.net:443…
#2 [internal] load build definition from buildkit-3769105386
#2 DONE 0.0s

#1 [internal] load .dockerignore
#1 DONE 0.0s

#1 [internal] load .dockerignore
#1 transferring context: 178B 0.1s done
#1 DONE 0.3s

#2 [internal] load build definition from buildkit-3769105386
#2 transferring dockerfile: 309B 0.1s done
#2 DONE 0.2s

#4 [internal] load metadata for Docker
#4 CANCELED

#3 [internal] load metadata for Docker
#3 ERROR: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

[internal] load metadata for Docker


x Error building service ‘angular-todo’: error building image ‘registry.cloud.okteto.net/ryanbas21/forgerock-javascript-sdk-angular-todo:okteto’: You are not authorized to push image ‘ryanbas21/forgerock-javascript-sdk-angular-todo:okteto’

looking at the dockerfile you shared before, could it be that the --from=base ... is wrong? shouldn’t it be --from=builder... ?