Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过ansible master在节点中创建docker容器_Docker_Ansible - Fatal编程技术网

通过ansible master在节点中创建docker容器

通过ansible master在节点中创建docker容器,docker,ansible,Docker,Ansible,我在AWS中有2个redhat实例。一个实例是Ansible master,另一个是node,其中都有docker。现在,在ansible master中,我有一个名为first的文件夹,Dockerfile中的文件夹如下所示,其中只安装了git FROM ubuntu:14.04 RUN apt-get update && apt-get install -y git 现在,我想在iam使用命令的节点或LocalHost中创建一个映像或运行一个容器 ansible

我在AWS中有2个redhat实例。一个实例是Ansible master,另一个是node,其中都有docker。现在,在ansible master中,我有一个名为first的文件夹,Dockerfile中的文件夹如下所示,其中只安装了git

FROM ubuntu:14.04    
RUN apt-get update && apt-get install -y git 
现在,我想在iam使用命令的节点或LocalHost中创建一个映像或运行一个容器

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

如何继续我的场景,在执行ansible即席命令时在节点中有一个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\u images
模块来运行构建,而不是shell

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

这是因为并非每台计算机上都存在localhost上的文件。你需要先把它们复制到某个地方

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\u images
模块来运行构建,而不是shell

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