Docker Community Forums

Share and learn in the Docker community.

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


(Ralph Kincade) #1

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


(Iwanttobefreak) #2

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


(David Maze) #3

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 https://docs.docker.com/engine/reference/builder/#/arg.

(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.)