2016-08-03 109 views
0

我想在Docker容器(与Ansible)中从BitBucket克隆私有存储库。我只是想尝试使这个工作,所以我复制我的公钥和私钥到容器中。我然后运行以下(FWICT这是对Ansible命令到简体版):Ansible Docker容器 - 克隆私人回购

docker exec -i web git clone [email protected]:user/repo.git 

而且我得到这个:

Cloning into 'repo'... 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 

作为一个方面说明,如果我跑:

docker exec -i -t web git clone [email protected]:user/repo.git 

我得到一个TTY,并得到提示输入SSH私钥密码(似乎无法与Ansible一起完成此操作)并回购了克隆。

所以问题是,如何克隆Docker容器中的私有存储库,而不需要-t?或者是否有人知道如何在Ansible的容器中复制私人回购?

+0

这听起来像你没有正确配置的关键 - 有你设置的相关权限容器内部的'〜/ .ssh'和'〜/ .ssh/id_rsa'? (FWIW你可能会考虑只加载'〜/ .ssh',而不是复制内容。) –

+0

id_rsa和id_rsa.pub都是400,所以我不认为权限是不幸的问题!虽然安装确实听起来更好。 – ellioseven

+0

为什么你需要密码保护密钥的原因是什么?你可以尝试使用可靠的expect模块来处理这个问题。 –

回答

1

我设法通过使用SSH代理转发(http://dchua.com/2016/01/15/ssh-agent-forwarding-with-your-docker-container)在我的任务,像这样四处找工作:

- set_fact: 
    ssh_auth_sock: "{{ lookup('env','SSH_AUTH_SOCK') }}" 

- name: Create container 
    docker_container: 
    name: "my_container" 
    image: "my_image" 
    ports: 
     - 80 
    volumes: 
     - "{{ playbook_dir }}/www:/var/www" 
     - "{{ ssh_auth_sock }}:/ssh-agent" 
    env: 
     SSH_AUTH_SOCK: /ssh-agent 

- name: Add container to inventory 
    add_host: 
    name: "web" 
    ansible_connection: docker 

- name: Clone Repository 
    git: 
    repo: "[email protected]:user/repo.git" 
    dest: "/var/www/html" 
    accept_hostkey: true 
    delegate_to: "web"