Saturday, 22 July 2017

continuous integration - CircleCI - Docker Login and Private Env Vars



I am configuring CircleCI to automatically build and upload to Docker Hub multiple container of an open source library I contribute to.



Everything works fine except when I try to login on docker using the CLI.
I think that my builds have trouble to access private env vars, however I tried everything to fix it...



My configuration file is the following:




version: 2
jobs:
build:
working_directory: ~/build
docker:
- image: docker:git
steps:
- checkout
- setup_remote_docker:
reusable: true

exclusive: true

- run:
name: Connect to Docker Hub
command: |
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}


I obtain the following error:




#!/bin/sh -eo pipefail
docker login -u $DOCKER_USER -p $DOCKER_PASS
"docker login" requires at most 1 argument.
See 'docker login --help'.

Usage: docker login [OPTIONS] [SERVER] [flags]

Log in to a Docker registry
Exited with code 1



The variables are of course defined:



enter image description here



I would like to precise, that this runs on a branch of the main project and that I don't need to run it on project forks.



I'm usually quite use to Travis CI, and this is so much easier.


Answer



I have found the answer, this container is very sensitive about the way env vars are defined:




This command should be used:



docker login -u "$DOCKER_USER" -u "$DOCKER_PASS"


alternatively, the following can be used:



echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...