Running git commands in private repo inside docker not working correctly


(Net Deamon) #1

I am working on bitbucket support for the docker_manager plugin. It does not work well with private repositories.

The plugin works by running the following commands to check the commits behind

latest_local_commit git rev-parse --short HEAD (local repo latest commit)

latest_origin_commit git rev-parse --short origin/master (server repo latest commit)

commits_behind git rev-list --count HEAD..origin/master to fetch the difference in number

The problem is that when I run the command of commit_behind in command line inside docker container plugin repository, I get 0.
But there are actually some commits made in the bitbucket private repository.
When I check locally in my machine, I rightly get the commits_behind number as 2.

I have added the ssh keys in /root/.ssh folder for the bitbucket repo. I am not able to understand why would the git command show 0 inside docker container (incorrect) but 2 in local machine(correct)


(Eli the Bearded) #2

This might be obvious, but have you checked that the ssh directory and files in it have tight permissions? That’s something ssh is picky about, and probably git using ssh, too. Mode 700 on directory, 600 on files is tight.


(Net Deamon) #3

I changed the .ssh folder to 700 permission, and its contents ( id_rsa and id_rsa.pub ) to 600.

But still I got 0 when I checked for commit_behind.


(Eli the Bearded) #4

What happens if you try to ssh to the git repo host from inside your app?

cd /var/discourse
./launcher enter app
ssh -v user@github.com.or.wherever

The last few lines for me look like:

debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

(I created an id_rsa key for this test, but it isn’t on gitbhub.) Do you see the key being offered?


(Net Deamon) #5

I got the key. Here are the logs

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to bitbucket.org ([104.XXX.XXX.1]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
authenticated via a deploy key.


You can use git or hg to connect to Bitbucket. Shell access is disabled.

(Eli the Bearded) #6

Well, it’s not an ssh issue then. I’m not git expert enough to suggest what to try next.


(Net Deamon) #7

Thanks anyways for the help :slight_smile: