91

I am trying to deploy a docker configuration with images on a private docker registry.

Now, every time I execute docker login registry.example.com, I get the following error message:

error getting credentials - err: exit status 1, out: Cannot autolaunch D-Bus without X11 $DISPLAY

The only solution I found for non-MacOS users was to run export $(dbus-launch) first, but that did not change anything.

I am running Ubuntu Server and tried with both the Ubuntu Docker package and the Docker-CE package.

How can I log in without an X11 session?

msrd0
  • 7,816
  • 9
  • 47
  • 82

7 Answers7

148

Looks like this is because it defaults to use the secretservice executable which seems to have some sort of X11 dependency for some reason. If you install and configure pass docker will use that instead which seems to solve the problem.

In a nutshell (from https://github.com/docker/compose/issues/6023)

sudo apt install gnupg2 pass 
gpg2 --full-generate-key

This generates a you a gpg2 key. After that's done you can list it with

gpg2 -k

Copy the key id (from the line labelled [uid]) and do

pass init "whatever key id you have"

Now docker login should work.

There are a couple of bugs logged on launchpad regarding this:

https://bugs.launchpad.net/ubuntu/+source/golang-github-docker-docker-credential-helpers/+bug/1794307

https://bugs.launchpad.net/ubuntu/+source/docker-compose/+bug/1796119

ChrisWue
  • 18,612
  • 4
  • 58
  • 83
  • 3
    Thanks for the answer. I switched to debian where things work just like they do on my arch dev machine so unfortunately I cannot test your solution – msrd0 Sep 10 '18 at 07:30
  • 1
    this solution gave me ``WARNING! Your password will be stored unencrypted in /home/adwised/.docker/config.json.`` on ubuntu18.04 – Phoenix Dec 13 '19 at 16:24
  • @MohammadMasoumi then `pass` wasn't installed properly or your docker install can't find it for some reason – ChrisWue Dec 16 '19 at 23:58
  • 2
    For me (ubuntu 18.04) the instruction "from the line labelled `[uid]`" was incorrect, instead needed to look for the ID in the entry labelled `pub`. (But answer still helpful, this is just an FYI in case others using it encounter the same) – Daryn Mar 19 '20 at 10:40
  • like @Neo I got "Warning! ... json;" (on debian 10.5) but followed by this advice to fix it : Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store – herve-guerin Nov 21 '20 at 00:10
  • This should be the correct answer, Thanks bro – Amor.o Feb 03 '21 at 08:57
  • Where does this `from the line labelled [uid])` mean? – Sutra Feb 04 '21 at 01:15
  • I got the `from the line labeled [uid]` meaning, it is from the output of the command `gpg2 --full-generate-key` in the first step. – Sutra Feb 04 '21 at 01:23
  • Solution working on Ubuntu 18.04 running on WSL 2 – ENDEESA Oct 16 '21 at 21:50
  • How much time does it take to generate a key? – nix86 Apr 28 '22 at 14:19
  • I was somehow able to fix the original problem by simply doing `apt install pass`. – vadipp May 31 '23 at 17:08
112

This works: sudo apt remove golang-docker-credential-helpers

oberstet
  • 21,353
  • 10
  • 64
  • 97
  • 10
    This works, and allows you to login, but your password will be stored unencrypted. Docker gives this notice: `WARNING! Your password will be stored unencrypted in $HOME/.docker/config.json.` – Azeirah May 11 '19 at 21:18
  • 1
    This `docker login` failure is apparently [a known issue](https://github.com/docker/compose/issues/6023) which is attributed to the `golang-docker-credential-helpers` Ubuntu package. This answer does work to allow you to `docker login` without a GUI, but as @tmuecksch mentioned, afterwards you will have to reinstall `docker-compose` (and the `golang...` package, if you want it). As mentinoed by @Azeirah, I did get a warning stating `my password will be stored unencrypted in ...`, but it was not actually stored anywhere that I could find. – travisw Oct 30 '19 at 13:40
  • 7
    Fixed the problem but also uninstalled `docker-compose`. – Jakob Drachmann Havtorn Feb 21 '20 at 12:36
  • 1
    The real question is, how to get the old behaviour (storing unencrypted in xyz) without **uninstalling** anything. – Marandil Nov 11 '20 at 16:00
  • mmmm, I don't like to store my passwords unencrypted ! – herve-guerin Nov 20 '20 at 23:54
  • Yep, this worked! And when vim /root/.docker/config.json, my token is not there, but a long not identified string for "auth". – RicHincapie Apr 17 '21 at 17:19
38

You can remove the offending package golang-docker-credential-helpers without removing all of docker-compose.

The following worked for me on a server without X11 installed:

dpkg -r --ignore-depends=golang-docker-credential-helpers golang-docker-credential-helpers

and then

echo 'foo' | docker login mydockerrepo.com -u dockeruser --password-stdin

Source:

bug reported in debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=910823#39
bug reported on ubuntu: https://bugs.launchpad.net/ubuntu/+source/docker-compose/+bug/1796119

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
dvanrensburg
  • 1,351
  • 1
  • 14
  • 21
28

secretservice requires a GUI. You can use pass without a GUI.

Unfortunately, Docker's documentation on how to configure Docker Credential Helpers is quite lacking. Here's a comprehensive guide how to configure pass with Docker (tested with Ubuntu 18.04):

1. Install the Docker Credential Helper for pass

# substitute with the latest version
url=https://github.com/docker/docker-credential-helpers/releases/download/v0.6.2/docker-credential-pass-v0.6.2-amd64.tar.gz

# download and untar the binary
wget $url
tar -xzvf $(basename $url)

# move the binary to a dir in your $PATH
sudo mv docker-credential-pass /usr/local/bin

# verify it works
docker-credential-pass list

2. Install and configure pass

apt install pass

# create a gpg2 key
gpg2 --gen-key
# if you have issues with lack of entropy, "apt install haveged" and try again

# create the password store using the gpg user id above
pass init $gpg_id

3. docker login

docker login

# You should not see any credentials stored in "auths" section.
# "credsStore": "pass" should have been automatically added.
# If the value is "secretservice", replace it with "pass".
cat ~/.docker/config.json

# verify credentials stored in `pass` store now
pass
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
wisbucky
  • 33,218
  • 10
  • 150
  • 101
16

There is a much easier answer than the ones already posted, which I found in a comment on https://github.com/docker/docker-credential-helpers/issues/105.

The solution is to rename docker-credential-secretservice out of the way e.g: mv /usr/bin/docker-credential-secretservice /usr/bin/docker-credential-secretservice.broken

Once you do this, docker login works regardless of whether or not docker-compose is installed. No other package additions or removals are necessary.

Aleksey Potapov
  • 3,683
  • 5
  • 42
  • 65
3

I've resolved this issue by uninstalling docker-compose which was installed from Ubuntu repo and installing docker-compose by official instruction at https://docs.docker.com/compose/install/#install-compose

Oleg Neumyvakin
  • 9,706
  • 3
  • 58
  • 62
  • 2
    the existence of a package manager is a huge advantage of linux over other operating systems. you usually don't want to install software without your distribution's package manager's awareness, for example by simply downloading software and copy it to `/usr/bin` or similar. the very obvious reason that you can update all software with just one command, another one is that you can have dependencies on other packages. – msrd0 Nov 02 '18 at 17:02
  • 1
    I resolved this issue by removing ubuntu from my system and used a system capable of running docker (I'm using debian for stable and fedora for staging). – msrd0 Nov 02 '18 at 17:03
  • @msrd0 lack of software isolation introduced by package system is a huge disadvantage of linux and the reason why such "hacks" like docker even exists. Back to the subject: this issue is introduced in Ubuntu package, wipe out Ubuntu is a not solution, so what workaround you are suggesting? – Oleg Neumyvakin Nov 03 '18 at 07:59
  • Yes you are absolutely right. Some distributions like fedora ship with selinux, but can't replace isolation done by docker. I asked this question hoping to get a workaround that is acceptable (like changing a config file or similar, not "disabling" the package manager), but haven't found one, so removing ubuntu was the only possible outcome for me – msrd0 Nov 03 '18 at 10:46
  • And the nice thing about docker is that you can have a `docker-compose.yml`, copy that to a different operating system with docker installed, copy the directory with all your docker volumes, and you won't notice any difference to your previous operating system. – msrd0 Nov 03 '18 at 10:47
  • it is good as a quick fix for those who not concern about updating it time to time – Seyed Ali Roshan Jan 10 '19 at 11:00
3

What helped me on Ubuntu 18.04 was:

  1. Following the steps in @oberstet 's post and uninstalling the golang helper
  2. Performing a login after the helper uninstall
  3. Reinstalling docker via sudo apt-get install docker
  4. Logging back in via sudo docker login
Stanislav
  • 31
  • 1