I want to add some automated builds for my docker containers, so I linked my bitbucket account with docker. Then I created an automated build and choose a private bitbucket repo.
If I now trigger a build the build failed with the following error message:
Failed to clone repository: Cloning into
'/tmp/build_xxxx'... Warning: Permanently added the
RSA host key for IP address '131.103.20.xxx' to the list of known
hosts. Permission denied (publickey). fatal: Could not read from
remote repository. Please make sure you have the correct access rights
and the repository exists.
For public repos the build works without any problems.
Any ideas why private repos are not working?
You need to add the rsa public key of the user in your Docker container that you are using to connect to BitBucket
Generally the public key is under:
~/.ssh/id_rsa.pub
or you can generate one:
user#host $ ssh-keygen
then commit your docker container to create a new image:
docker commit <container-id> mycontainer:0.1
Related
I am trying to connect my jenkins server to my private repository on gitlab.com.
I have already added the API access token of gitlab to my jenkins server and added the Jenkins public key to the ssh-keys of gitlab account.
Upon adding my gitlab repository to my jenkins pipeline I get below error:
Failed to connect to repository : Command "git ls-remote -h -- git#gitlab.com:user_name/repo_name.git HEAD" returned status code 128:
stdout:
stderr: Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
When I try to run the following command on my Jenkins server:
ssh -T git#gitlab.com:user_name/repo_name.git
I get the following error:
ssh: Could not resolve hostname gitlab.com:user_name/repo_name.git: Name or service not known
I am not able to figure out the reason why my Jenkins server is unable to access the repository even after providing the SSH Keys and the Access Token.
API access token of gitlab
That would be use for HTTPS access.
added the Jenkins public key to the ssh-keys of gitlab account
That is relevant for SSH URL, and means you need to set the right credentials in your Jenkins job (the credential referencing the Jenkins private key, whose public key was published to GitLab)
I would test first on Jenkins server:
ssh -Tv git#gitlab.com
Check also the content of your Jenkins server running account ~/.ssh/config file for any gitlab.com Host entry.
I have generated a pubic SSH key on my Ubuntu 20.04 server with the user Jenkins, and my key is stored below :
/var/lib/jenkins/.ssh/id_rsa.pub
I have set that public Key on my Gitlab SSH parameters, And I had also create a Credentials in Jenkins for SSH Private key, where i pasted the private key i had generate for my Jenkin's user in linux 20.04 remote server.
When i try to clone the projet using SSH, i get the error :
Failed to connect to repository : Error performing git command: /usr/lib/git-core ls-remote -h git#gitlab.com:project/repository.git HEAD*
Need a helping hand to solve this problem.
enter image description here
First, check that your key is indeed considered when doing ssh with the jenkins account:
ssh -Tv git#gitlab.com
You will see where SSH is looking for your keys, and if /var/lib/jenkins/.ssh/id_rsa is used.
You should see a welcome message.
Second, Check the Jenkins logs to see if there is any additional clues.
You might need to use an SSH key using the old PEM format:
ssh-keygen -m PEM -t rsa -P "" -f afile
I'm on Ubuntu Linux Server 20.04 and this is my first time pushing something to Docker so I just created a dummy container locally and it worked. Following some tutorials online, the hello-world example also works just fine.
Here's what I've tried:
I create a repo online
I've tried all of this for both public and private repos.
I just have a stardard account, this is not an organization.
docker login (Which succeeds)
I've also tried docker login -u <username>
I've tried with and without the pass program (Both succeed in logging in)
To make sure it's not reporting a false"success" message I tried using an incorrect password and it failed accordingly so the login appears to work.
docker tag <local repo name>:latest <username>/<online repo name>:v1
I've tried a myriad of other ways such as the following but they all produce the same error
docker tag <local repo name>:latest <username>/<repo name>:latest
docker tag <local repo name> <username>/<repo name>:latest
docker tag <local repo name>:latest <username>/<repo name>:v1
docker tag <local repo name> <username>/<repo name>:v1
docker tag <local repo name>:latest <username>/<repo name>
docker tag <local repo name> <username>/<repo name>
docker push <username>/<online repo name>:v1
I've also tried docker push <username>/<online repo name>
This is the output
The push refers to repository [docker.io/<username>/<online repo name>]
3c8373fcfed2: Preparing
dc881c014b38: Preparing
933337b6e971: Preparing
10e1cb1c03c2: Preparing
770786057cc0: Preparing
570175f149e2: Waiting
3e207b409db3: Waiting
denied: requested access to the resource is denied
At this point I've just given up, I don't understand why it's being denied and not pushing but I've gone through 2 Google pages of links trying to research this spanning 2 days so I don't know what else to do.
In attempt to not store my docker password unencrypted I'm using the recommended pass program on the Docker website. If I give up and just allow my password to be unencrypted it works. This is an issue with pass or Docker's communication with pass. I'm not happy about having to have my password unencrypted but it's either that or I can't push to Docker Hub.
There are 4 solutions for not storing your password unencrypted and the only one for Linux servers is pass.
I have private GitLab server running in the cloud (bitnami image). I have a custom domain registered with the public IP of Gitlab Server and letsencrypt certificate generated for this domain. I can access gitlab server by https://mycustomdomain/.
I have installed gitlab-runner on linux host and successfully registered (docker executor) with gitlab server (https://mycustomdomain/).
Now when i then run the pipeline, it fails with following message:
Pulling docker image node:latest ...
Using docker image sha256:2a0d8959c8e1b967d926059e555fdd23926c8fff809a0cf5fab373e694bbce64 for node:latest ...
Running on runner-PcudM7CB-project-1-concurrent-0 via my-gitlab-worker...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/root/microcities/.git/
Created fresh repository.
fatal: unable to access 'https://<my gitlab public IP>/root/microcities.git/': SSL: no alternative certificate subject name matches target host name 'my gitlab public IP'
ERROR: Job failed: exit code 1
Why does the runner/docker container refer to gitlab server by it's IP rather than by domain name?
Solution is to update the gitlab server configuration. In my case that means running
cd /opt/bitnami/apps/gitlab
sudo ./bnconfig --machine_hostname DOMAIN-NAME
This is well covered in bitnami documentation, my bad I did miss this step.
I created a dockerfile which generates the docker image with my node application. My application depends on my another application which is added as dependency using git ssh.
When docker build runs npm install, it fails with error code 128. I understand it is because i do not have valid ssh token to access repo. How can i create one and have my docker build pass?
You can use ssh-keygen -t rsa to generate your local machine's key (do not provide any passcode for simplicity) that can be used for authentication. Now adding that key for git access depends on where your repository is i.e is it on hosted sites like bitbucket/github or just your another linux machine.
For repository on local server run below commands on your local machine to add your public key (id_rsa.pub) to git server.
eval "$(ssh-agent -s)"
ssh-add
ssh-copy-id user#git-server
For hosted sites you get the option to add the public-key under your profile settings.
Note: do not forget to add below in ~/.ssh/config file on your local machine to avoid the unknown host exception
Host bitbucket.org
StrictHostKeyChecking no
Host <git-server-ip>
StrictHostKeyChecking no
For more information on generating key please refer to https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html