Héctor
Héctor

Reputation: 26034

Ansible task for run Docker container from private registry

I have a private Docker registry runnning in 172.20.20.20 in port 5000. And I have pushed the image pruebasjeje to it.

Now, I need to pull and run the image using Ansible task:

   - name: run container
     docker:
       registry: 172.20.20.20:5000
       insecure_registry: true
       image: pruebasjeje
       state: reloaded
       pull: always
       ports:
        - "8080:8080"

But when I execute it, I get this error:

fatal: [localhost]: FAILED! => {"changed": false, "changes": ["{\"status\":\"Pulling repository docker.io/library/pruebasjeje\"}\r\n", "{\"errorDetail\":{\"message\":\"Error: image library/pruebasjeje:latest not found\"},\"error\":\"Error: image library/pruebasjeje:latest not found\"}\r\n"], "failed": true, "msg": "Unrecognized status from pull.", "status": ""}

It seems that is looking for the image in docker.io. How should I write my task in order to do what I want?

Thanks.

Upvotes: 2

Views: 9352

Answers (1)

udondan
udondan

Reputation: 59969

Not sure if it is how it should be done, but this is how I do it:

   - name: run container
     docker:
       insecure_registry: true
       image: 172.20.20.20:5000/pruebasjeje
       state: reloaded
       pull: always
       ports:
        - "8080:8080"

I just started with Docker myself. Here are the tasks I have for setting up Docker on my target host (CentOS 7):

- name: Install epel repo
  yum:
    name: "http://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_userspace_architecture }}{{ '/' if ansible_distribution_major_version < '7' else '/e/' }}epel-release-{{ ansible_distribution_major_version }}-5.noarch.rpm"
    state: present
  become: yes

- name: Install Docker
  yum:
    name: "{{ item }}"
    state: latest
    enablerepo: epel
  with_items:
    - device-mapper
    - docker-engine
    - python-pip
  become: yes

- name: Install docker-py
  pip:
    name: docker-py
  become: yes

- name: Add registry cert
  copy:
    src: registry.crt
    dest: /etc/docker/certs.d/{{ docker_registry_host }}/ca.crt
  become: yes

- name: Allow access to insecure registry
  lineinfile:
    dest: /usr/lib/systemd/system/docker.service
    regexp: ^ExecStart=
    line: ExecStart=/usr/bin/docker daemon -H fd:// --insecure-registry {{ docker_registry_host }}:5000
  become: yes

- name: Start Docker service
  service:
    name: docker
    state: started
    enabled: yes
  become: yes

Upvotes: 8

Related Questions