Answers: <p>You mentioned that the auth key is stored in Jenkins credentials and are available as environment variables, if so, then your half task is already done; what you can probably do from here is, use those environment variables to perform docker login (assuming USERNAME and PASSWORD are the Jenkins credentials variable), use the below command to login</p>
  
  <pre><code>docker login your.docker-registry.com -u $USERNAME -p $PASSWORD
  </code></pre>
  
  <p>This assumes, that your registry has SSL enabled, if so, don't forget to place the registry certificates under the below name on your Jenkin host</p>
  
  <pre><code>/etc/docker/certs.d/your.docker-registry/ca.crt
  </code></pre>
  
  <p>Post this, you would be able to push image to the registry</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-18T09:32:09.130Z
Answers: 2019-01-18T09:32:09.130Z
Answers: rebelution
Body: <p>I'm trying to set up Jenkins CI pipeline which will be used to build docker images. I have my auth key stored in Jenkins credentials and I want it to be loaded on start in placed in some environment variable (already done).</p>
  
  <p>Is it possible that Docker will read that environment variable and use the key for authenticating to my container registry?
  Or maybe I can pass it somehow via command line?</p>
  
  <p>I've tried searching for that in the docs, but only thing I found is that I can specify that values in <code>config.json</code> and specify the location of that. This is not the best option IMO.</p>
  
  <p>Any ideas? Thanks in advance.</p>
  
Tags: <docker><registry>
Title: Set container registry auth key via command line/env variable
UserDisplayName: Morishiri
ThreadText: # Set container registry auth key via command line/env variable
  
  (Asked by: username_0 on 2018-08-07)
  
  I'm trying to set up Jenkins CI pipeline which will be used to build docker images. I have my auth key stored in Jenkins credentials and I want it to be loaded on start in placed in some environment variable (already done).
  
  Is it possible that Docker will read that environment variable and use the key for authenticating to my container registry?
  Or maybe I can pass it somehow via command line?
  
  I've tried searching for that in the docs, but only thing I found is that I can specify that values in `config.json` and specify the location of that. This is not the best option IMO.
  
  Any ideas? Thanks in advance.
  
  **Tags:** docker, registry
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-18. Score: 1
  
  You mentioned that the auth key is stored in Jenkins credentials and are available as environment variables, if so, then your half task is already done; what you can probably do from here is, use those environment variables to perform docker login (assuming USERNAME and PASSWORD are the Jenkins credentials variable), use the below command to login
  
  ```
  docker login your.docker-registry.com -u $USERNAME -p $PASSWORD
  
  ```
  
  This assumes, that your registry has SSL enabled, if so, don't forget to place the registry certificates under the below name on your Jenkin host
  
  ```
  /etc/docker/certs.d/your.docker-registry/ca.crt
  
  ```
  
  Post this, you would be able to push image to the registry
  
  
  ---
  
  