connecting to Docker Hub in travis CI - docker

I tried to connect to my dockerHub via travis ci
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
but i got this error
Error: Cannot perform an interactive login from a non TTY device

Try this instead:
docker login --username "$USER" --password "$PWD"

Related

Non-interactive docker login in Github Actions

I am trying to run this command inside a Github Actions step running on a Windows agent:
echo ${ACR_SERVICE_PRINCIPAL_PASSWORD} | docker login -u ${ACR_SERVICE_PRINCIPAL} --password-stdin spetestregistry.azurecr.io
But it returns this error:
Error: Cannot perform an interactive login from a non TTY device
Then I tried this command:
echo ${ACR_SERVICE_PRINCIPAL_PASSWORD} | winpty docker login -u ${ACR_SERVICE_PRINCIPAL} --password-stdin spetestregistry.azurecr.io
Which produced this error:
stdin is not a tty
Does anyone know how I can do this?
Finally figured out that I was using the Github secrets variable incorrectly. This works:
echo ${{ secrets.ACR_SERVICE_PRINCIPAL_PASSWORD }} | docker login --username ${{ secrets.ACR_SERVICE_PRINCIPAL }} --password-stdin spetestregistry.azurecr.io

Jenkins can not execute docker login via ssh-agent

I create the Jenkins pipeline to deploy my app. I built and push docker image to AWS ECR. The final step is executing ssh to deployment server (EC2) and run docker container based on last built image.
This is my script:
stage('Deploy') {
steps {
script {
sshagent(['ssh-cridentials']) {
sh "ssh -o StrictHostKeyChecking=no jenkins#host sudo docker rm -f myapp"
sh "ssh -o StrictHostKeyChecking=no jenkins#host sudo docker image prune -a -f"
sh "ssh -o StrictHostKeyChecking=no jenkins#host \"cat /opt/aws/password.txt | sudo docker login --username AWS --password-stdin $ecrURI & sudo docker run -p 80:80 -d --name=myapp $imageURI\""
}
}
}
}
However, Jenkins built fail and I got the error:
docker: Error response from daemon: Get https://xxx: no basic auth credentials.
This command couldn't login to ECR.
But it works successfully if I execute the same command on deployment server.
Looks like something wrong with your escape character, try without using that (I believe you have valid ecr url in variable $ecrURI)
sh "ssh -o StrictHostKeyChecking=no jenkins#host cat /opt/aws/password.txt | sudo docker login --username AWS --password-stdin $ecrURI & sudo docker run -p 80:80 -d --name=myapp $imageURI"

Bypassing the --password-stdin warning (docker)

Another day, another problem with docker.
I have a Windows server 2019, docker version 18.09.03 and I want to get my images to ECR.
For certain reasons, I can't have the warning docker : WARNING! Your password will be stored unencrypted
My deployment tool considers it as an error and thus, doesn't deploy. I have therefore been looking how to use --password-stdin in the "correct" manner. Which isn't going very well.
Here is the Powershell script I am using right now.
#First step to create the file
aws ecr get-login --no-include-email | Out-File -FilePath FILEPATH
#Second step to filter the file and just get the password.
-split #(Get-Content -Path FILEPATH) |Select-Object -Index 5 | Out-File -FilePath FILEPATH
#Get authorized but stdin warning??
cat FILEPATH | docker login -u AWS --password-stdin https://NUMBER.dkr.ecr.eu-west-1.amazonaws.com
I am passing the password into a file then stdin from it, it works but it returns the warning.
I have tried that comment too (https://github.com/aws/aws-cli/issues/2875#issuecomment-433565983) but it doesn't accept the flags neither. I do
aws ecr get-login --no-include-email --region eu-west-1 --password-stdin and Unknown options: --password-stdin
aws ecr get-login --region us-east-1 --print-password-only
--print-password-only is unknows as well)
I am FULLY starting to get annoyed and frustrated by now. Any help would be appreciated, thanks!
Use --password-stdin by providing the password via stdin like so:
echo <my_password> | docker login -u <username> --password-stdin
Or, if fetching the password from a file, like so:
cat <my_file> | docker login -u <username> --password-stdin
In order to login without any warning one could try --password-stdin but it is important to remember that the password need to be provided by stdin in this case. So --password-stdin <my-pwd> won't work.
One could try
echo <my-pwd> | docker login <registry-name> -u <username> -p <password>
or the following could be done
cat ~/my-pwd.txt | docker login <registry-name> -u <username> -p <password>
Incase more information refer to the question : Docker: Using --password via the CLI is insecure. Use --password-stdin
Could just redirect stderr, special bonus using a gcloud auth token.
docker login https://us.grc.io -u oauth2accesstoken --password-stdin <<< $(gcloud auth print-access-token --quiet) 2>/dev/null
Login Succeeded

How to avoid password when using sudo in gitlab-ci.yml?

I have a private docker repository where i store my build images.
I did copy my registry certificates and updated my /etc/hosts file to authenticate registry from my local machine.
I could login to registry with 'sudo docker login -u xxx -p xxx registry-name:port'
But when i try same docker login command from gitlab-ci stage, it is failing with this error:
sudo: no tty present and no askpass program specified.
This is how i'm trying to achieve this.
ssh manohara#${DEPLOY_SERVER_IP} "sudo docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}"
I also tried adding this gitlab-runner ALL=(ALL) NOPASSWD: ALL at the bottom of /etc/sudoers file, but no luck
Where am i going wrong?
According to this Source you can use
ssh -t remotehost "sudo ./binary"
The -t allocates a pseudo-tty.
Or in your example:
ssh -t manohara#${DEPLOY_SERVER_IP} "sudo docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}"

Docker login failing (at most 1 argument)

I am failing to login to a remote docker registry using a command of the form:
docker login –u my-username –p my-password registry.myclient.com
The error I get is the following:
"docker login" requires at most 1 argument.
See 'docker login --help'.
Usage: docker login [OPTIONS] [SERVER]
How can login to the remote registry?
You don't have tacks in front of your options, it's some other dash like character. Try this instead:
docker login -u my-username -p my-password registry.myclient.com
While it looks similar, -u and -p are not the same as –u and –p.
This one worked for me if ci environment is in play:
echo ${MVN_PASSWORD} | docker login -u ${MVN_USER} --password-stdin ${MVN_URL}
these variables need to be set up via Settings > CI/CD > Variables (gitlabci example)
Here is what worked for me:
I saved the password in a file called my_password.txt.
Then, I ran the following command:
cat ~/my_password.txt | docker login -u AWS --password-stdin https://{YOUR_AWS_ACCOUNT_ID}.dkr.ecr.{YOUR_AWS_REGION}.amazonaws.com

Resources