使用 ansible 模块 "docker_image" 模拟 "docker build -f"
Simulation "docker build -f" with ansible module "docker_image"
当我构建 docker 图像时,我想在 Docker 文件中添加指令 "COPY",其中的目录位于当前构建目录之外(Dockerfile 被放置) - 我正在使用这样的东西:
docker build -f centos6-fresh/Dockerfile -t test/c6-fresh .
现在我想通过 ansible 来配置容器和构建 docker 图像。
当然,我可以使用 shell、命令或原始模块来完成,但我看到了 Docker.
的特殊模块
所以我使用了模块 "docker_image"
- name: Build test image
docker_image:
path: /docker/build_env/test
name: test_build
tag: v0
当然我有错误。
是否有任何选项可以设置从哪个目录开始构建过程?
UPD
我需要这些操作的案例示例:
我有带 ansible 的管理节点(我的笔记本电脑)和带容器的 Docker 主机。 Ansible 目录正在将 git 配置到 Docker 服务器。
通常我在 Docker 主机上的目录 build_env 中构建镜像:
[root@docker build_env]# ls -1
ansible
centos6-fresh
centos7-fresh
debian8-fresh
templates
test
所以在 ansible 目录中 运行 "git pull" 之后,我 运行 类似
docker build -f centos6-fresh/Dockerfile -t test/c6-fresh .
Docker文件包含:
COPY ansible /etc/ansible
就像我们现在一样,docker 防止在 COPY 或 ADD 选项中使用 "COPY ../ansible" 之类的东西。
根据 docker_image documentation,有一个 dockerfile
选项与 -f
命令行选项完全类似。所以你只需要:
- name: Build test image
docker_image:
path: /docker/build_env/
name: test_build
tag: v0
dockerfile: centos6-fresh/Dockerfile
当我构建 docker 图像时,我想在 Docker 文件中添加指令 "COPY",其中的目录位于当前构建目录之外(Dockerfile 被放置) - 我正在使用这样的东西:
docker build -f centos6-fresh/Dockerfile -t test/c6-fresh .
现在我想通过 ansible 来配置容器和构建 docker 图像。 当然,我可以使用 shell、命令或原始模块来完成,但我看到了 Docker.
的特殊模块所以我使用了模块 "docker_image"
- name: Build test image
docker_image:
path: /docker/build_env/test
name: test_build
tag: v0
当然我有错误。
是否有任何选项可以设置从哪个目录开始构建过程?
UPD 我需要这些操作的案例示例:
我有带 ansible 的管理节点(我的笔记本电脑)和带容器的 Docker 主机。 Ansible 目录正在将 git 配置到 Docker 服务器。
通常我在 Docker 主机上的目录 build_env 中构建镜像:
[root@docker build_env]# ls -1
ansible
centos6-fresh
centos7-fresh
debian8-fresh
templates
test
所以在 ansible 目录中 运行 "git pull" 之后,我 运行 类似
docker build -f centos6-fresh/Dockerfile -t test/c6-fresh .
Docker文件包含:
COPY ansible /etc/ansible
就像我们现在一样,docker 防止在 COPY 或 ADD 选项中使用 "COPY ../ansible" 之类的东西。
根据 docker_image documentation,有一个 dockerfile
选项与 -f
命令行选项完全类似。所以你只需要:
- name: Build test image
docker_image:
path: /docker/build_env/
name: test_build
tag: v0
dockerfile: centos6-fresh/Dockerfile