我正在尝试使用 Ansible 的 在机器上构建一堆 docker。 docker_image 模块。
我构建了 1 个“基础”docker 镜像,它在所有后续 docker 镜像中用作 FROM 镜像。这在手动发出构建命令时有效:
sudo docker build -t base .
sudo docker build -t postgres .
但是,当我尝试对 Ansible 模块执行相同操作时,第二个图像(以及使用“基本”图像的所有后续图像)失败并出现以下错误:
TASK: [Docker | Build postgres] ************************************
failed: [192.168.1.120] => {"changed": true, "failed": true, "image_id": null}
msg: Error: Error: image base:latest not found
Log:Step 0 : FROM base
FATAL: all hosts have already failed -- aborting
我的剧本中的条目是:
- name: Docker | Build base
docker_image: path="/home/xx/data/dockers/base/" name="base" state=present
- name: Docker | Build postgres
docker_image: path="/home/xx/data/dockers/postgresql/" name="postgres" state=present
当它失败时,机器上存在“基础”图像,我可以通过检查
docker images
来验证它。 .后续图像(在本例中为 postgres)在进行手动构建时也不会失败。来自 Dockerfiles 的相关摘录:
基础 Dockerfile:
FROM ubuntu
MAINTAINER me
RUN apt-get update
RUN apt-get install -y \
software-properties-common \
wget \
git \
unzip \
nano \
vim-tiny
CMD bash
Postgres Docker 文件:
FROM base
MAINTAINER me
RUN groupadd -r postgres && useradd -r -g postgres postgres
...
因此 Ansible 努力使用另一个图像作为基础图像来构建图像。我确定问题不在于 Dockerfile,因为我可以手动构建图像。我只是想用 Ansible 自动化构建,这给了我问题。
有什么建议吗?
最佳答案
这里的问题是 docker-py
最近有一些更新的模块将首先探测图像集线器。 docker-py
不使用命令行工具,它使用自己的 docker api 实现并以自己的方式做事。
我建议你建立一个私有(private)中心。你需要一个下午来适应这个想法,然后开始为你的容器镜像添加前缀。在构建图像时推送。启动它们时拉动。在你的剧本中分离这些问题。在某些情况下,忘记使用 ansible docker 模块,只需通过 ansible 的 shell 模块调用 docker cli。这是一篇关于 ansible 和 docker 的好文章。 http://opensolitude.com/2015/05/26/building-docker-images-with-ansible.html
关于docker - 使用 Ansible docker_image 构建 Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31134518/