Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 340
Jonathan DEKHTIAR Avatar asked Oct 31 '25 07:10

Jonathan DEKHTIAR


1 Answers

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
like image 63
Jonathan DEKHTIAR Avatar answered Nov 03 '25 00:11

Jonathan DEKHTIAR