Ansible Docker连接错误

时间:2016-04-12 21:18:42

标签: docker ansible docker-registry

我正在运行ansible 1.9版本,docker-py版本1.1.0和Docker 1.9.1。我有一个运行在http://registry.myserver.com:5000的私有不安全的docker注册表。

我有一个ansible任务,使用来自此远程注册表的已拉图像启动容器:

---
  - name: Start User Service Container
    docker:
        name: userService
        image: user-service
        registry: registry.myserver.com:5000
        state: running
        insecure_registry: yes
        expose:
          - 8355

但是,目前返回以下错误:

  

失败:[bniapp1] => {“已更改”:false,“failed”:true}   msg:ConnectionError(ProtocolError('Connection aborted。',error(2,'No such file or directory')),)

详细输出:

<54.229.16.155>
<54.229.16.155> image=discovery-service registry=http://registry.myserver.com:5000 name=discoveryService state=running
<54.229.16.155> IdentityFile=/home/nfrstrctrescd/bni-api.pem ConnectTimeout=10 PasswordAuthentication=no KbdInteractiveAuthentication=no User=centos ControlPath  =/home/nfrstrctrescd/.ansible/cp/ansible-ssh-%h-%p-%r PreferredAuthentications=g  ssapi-with-mic,gssapi-keyex,hostbased,publickey ControlMaster=auto ControlPersis  t=60s
<54.229.16.155>
<54.229.16.155> IdentityFile=/home/nfrstrctrescd/bni-api.pem ConnectTimeout=10 'sudo -k && sudo -H -S -p "[sudo via ansible, key=hxhptjipltjnteknbbxkqgcdwvwshen  p] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-hxhptjipltjnteknbbxkqgc  dwvwshenp; LANG=C DOCKER_HOST=tcp://127.0.0.1:2376 DOCKER_TLS_VERIFY=1 LC_CTYPE=  C DOCKER_CERT_PATH=/opt/docker/certs /usr/bin/python /home/centos/.ansible/tmp/a  nsible-tmp-1460499148.45-268540710837667/docker; rm -rf /home/centos/.ansible/tm  p/ansible-tmp-1460499148.45-268540710837667/ >/dev/null 2>&1'"'"'' PasswordAuthe  ntication=no KbdInteractiveAuthentication=no User=centos ControlPath=/home/nfrst  rctrescd/.ansible/cp/ansible-ssh-%h-%p-%r PreferredAuthentications=gssapi-with-m  ic,gssapi-keyex,hostbased,publickey ControlMaster=auto ControlPersist=60s
failed: [bniapp1] => {"changed": false, "failed": true}
msg: ConnectionError(ProtocolError('Connection aborted.', error(2, 'No such file or directory')),)

注意:当我在远程服务器上手动运行容器时,图像被拉出并且容器正确启动:

docker run registry.myserver.com:5000/user-service

1 个答案:

答案 0 :(得分:0)

我收到此错误是因为我的docker守护程序未运行。在启动docker之前添加以下ansible代码为我修复它:

# Start Docker Service
- name: Start Docker service
  service: name=docker state=started
  become: yes
  become_method: sudo
- name: Boot Docker on startup
  service: name=docker enabled=yes
  become: yes
  become_method: sudo