我在端口172.20.20.20
的{{1}}中运行了私有Docker注册表。我已将图像5000
推到了它。
现在,我需要使用Ansible任务拉动并运行图像:
pruebasjeje
但是当我执行它时,我收到了这个错误:
致命:[localhost]:失败! => {"更改":false,"更改": [" {\" status \":\"拉动存储库 docker.io/library/pruebasjeje\"}\r\n" ;, " {\" errorDetail \":{\" message \":\"错误:图片 library / pruebasjeje:最新未找到\"},\"错误\":\"错误:图片 library / pruebasjeje:最新未找到\"} \ r \ n"],"失败":true," msg": "来自拉的无法识别状态。","状态":""}
似乎正在寻找docker.io中的图像。我该怎么写我的任务才能做我想做的事?
感谢。
答案 0 :(得分:2)
不确定它是否应该如何完成,但我就是这样做的:
- name: run container
docker:
insecure_registry: true
image: 172.20.20.20:5000/pruebasjeje
state: reloaded
pull: always
ports:
- "8080:8080"
我刚开始使用Docker。以下是我在目标主机(CentOS 7)上设置Docker的任务:
- 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