Docker - Error: Cannot perform an interactive login from a non TTY device (GCP Service Account)

Viewed 12567

The command docker login -u _json_key --password-stdin https://gcr.io < ~/service-account.json works locally, but when I try to run it in a CI environment like Github Actions, I get the following error.

Error: Cannot perform an interactive login from a non TTY device

##[error]Process completed with exit code 1.

2 Answers

The oauth2accesstoken authentication strategy worked for me.

  1. Login to gcloud cli using service account

gcloud auth activate-service-account --key-file=${HOME}/service-account.json

  1. Print access token and use it to log into docker

gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io

It seems you are impersonating a service account with an authentication token to login docker. You can obtain an access token for the service account. Since the token is short-lived, request it less than an hour before you use it to connect with the Container Registry.

The steps are documented here.

Related