docker集装箱通过可靠的主人在节点中创build

我在AWS中有2个redhat实例。 一个例子是Ansible master和其他节点都有docker在里面。 现在在一个可靠的主人,我有一个名为第一个文件夹,并在该Dockerfile存在像下面哪里只有git正在安装

FROM ubuntu:14.04 RUN apt-get update && apt-get install -y git 

现在我想创build一个图像或运行iam使用命令的节点或locallhost中的容器

 ansible all -s -m shell -a "docker build -t first:latest ." 

我得到下面的错误

 localhost | FAILED | rc=1 >> unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/test/Dockerfile: no such file or directory 

如何继续我的scheme在执行一个可靠的ad-hoc命令时在节点中有一个docker图像或docker容器?

这是因为你在本地主机上的文件不在每台机器上。 您需要先将这些文件复制到某个位置。

 ansible all -s -m "synchronize" -a "src=./ dest=/tmp/build/" 

这将复制你的当前文件夹到/tmp/build ,如果你只想复制Dockerfile,你也可以使用文件模块。 然后你应该运行build命令

 ansible all -s -m shell -a "docker build -t first:latest /tmp/build" 

这回答你的问题,但是这样的方法仍然是不正确的,因为你应该使用docker_images模块来运行构build而不是shell

 ansible all -s -m docker_image -a "name=first tag=latest path=/tmp/build state=build force=yes"