Reputation: 81
While I build docker image and I want to add the instruction "COPY" in Dockerfile with a directory which is outside of current build directory(place where Dockerfile is placed) - I'm using something like this:
docker build -f centos6-fresh/Dockerfile -t test/c6-fresh .
Now I want to do provisioning containers and building docker images through ansible. Of course I'm able to do it with shell, command or raw modules, but I saw special module for Docker.
So I've used module "docker_image"
- name: Build test image
docker_image:
path: /docker/build_env/test
name: test_build
tag: v0
And certainly I've got the error.
Is there any option, to set from which directory, building process must be started?
UPD The example of case where I need these manipulations:
I have management node(my laptop) with ansible and Docker host with containers. Ansible dir is provisioning with git to Docker server.
Usually I build an image in the directory build_env on the Docker host:
[root@docker build_env]# ls -1
ansible
centos6-fresh
centos7-fresh
debian8-fresh
templates
test
So after run "git pull" in ansible directory, I run something like
docker build -f centos6-fresh/Dockerfile -t test/c6-fresh .
Dockerfile consists:
COPY ansible /etc/ansible
As we now, docker prevents to use something like "COPY ../ansible" in the COPY or ADD options.
Upvotes: 0
Views: 790
Reputation: 311238
According to the docker_image documentation, there is a dockerfile
option that is an exact analog to the -f
command line option. So you would just need:
- name: Build test image
docker_image:
path: /docker/build_env/
name: test_build
tag: v0
dockerfile: centos6-fresh/Dockerfile
Upvotes: 1