How can I use docker login to a private registry or Jenkins in a dockerfile?

How can I use docker login to a private registry or Jenkins in a dockerfile?

I want to use docker login each time a build is run from an image

I wanted to use the FROM instruction on the first part of the file to reference an images that I have in Jenkins , but want to use docker login ??? I guess to authenticate to Jennkins EACH time that I start the image I alos want to protect the password as well , how can I do this

Thanks in advance

You can do that.
Dockerfile:
FROM debian
ARG USER
ARG PASSWORD

And build image:
docker build --build-arg USER=your_user --build-arg PASSWORD=your_password

You almost certainly don’t want to do this: it makes the username and password visible to anyone who cares to run docker history to look at your image. See the note at Dockerfile reference | Docker Documentation.

(It also doesn’t answer the OP’s issue: if their Dockerfile is FROM private-registry.example.com/image, I don’t think this will get valid login credentials to it.)