# How can I use in my Dockerfile a secret coming from an ENV

**URL:** <https://community.okteto.com/t/how-can-i-use-in-my-dockerfile-a-secret-coming-from-an-env/1418>\
**Category:** Not sure?\
**Created:** [July 28, 2025, 10:56am UTC](https://community.okteto.com/t/how-can-i-use-in-my-dockerfile-a-secret-coming-from-an-env/1418 "2025-07-28T10:56:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mario](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/mario/32/292_2.png) [@mario](https://community.okteto.com/u/mario)\
**Post date:** [July 28, 2025, 10:56am UTC](https://community.okteto.com/t/how-can-i-use-in-my-dockerfile-a-secret-coming-from-an-env/1418/1 "2025-07-28T10:56:16Z")

</div>

I want to send to my build a token to access from the Dockerfile to my private npm repository but Okteto only accepts in the build section the format of file.

In my case Im using Deploy Preview Environments Action from Okteto.

How can I do it?

---

<div class="post-metadata">

**Author:** ![mario](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/mario/32/292_2.png) [@mario](https://community.okteto.com/u/mario)\
**Post date:** [July 28, 2025, 11:02am UTC](https://community.okteto.com/t/how-can-i-use-in-my-dockerfile-a-secret-coming-from-an-env/1418/2 "2025-07-28T11:02:33Z")

</div>

At the moment we only accept it in the format of files: [Okteto Manifest Reference | Okteto Documentation](https://www.okteto.com/docs/reference/okteto-manifest/#build-object-optional)

The way to do it is to get the ENV variable value and use it in a file and then pass it to the Dockerfile and export it to ENV variable.

Steps would be:

- Add in **Admin/Admin Variables** in the UI of Okteto an Env called:` NPM_TOKEN=mynpmaccesstoken`

- Then add a file to the repository call for example `.npm_token` with the content: `$NPM_TOKEN`  
This will get the value from the UI variable

- In the Okteto manifest `build` section I get the content of that file:

```auto
build:
  api:
    context: api
    secrets:
      npmrc: .npm_token

```

- And finally mount that secret in the Dockerfile ([Secrets | Docker Docs](https://docs.docker.com/build/building/secrets/#using-build-secrets)):

```auto
RUN --mount=type=secret,id=npmrc \ 
    export NPM_READONLY_TOKEN=$(cat /run/secrets/npmrc) && echo $NPM_READONLY_TOKEN

```

Instead of using` echo` using your command that will consume the value.
