Simulation “docker build -f” with ansible module “docker_image”

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 .

  • Udeploy not projecting the data
  • When moving the Docker in Ansible, it does not allow you to specify the dns
  • Docker Volumes: Docker Volume does not get mounted correctly on Amazon Linux
  • Docker image is not visible when I run docker ps
  • Docker, how to deal with ssh keys, known_hosts and authorized_keys
  • Error while changing hostname inside docker container
  • 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.

  • Cannot download Docker image from repository
  • Docker: hashicorp/boot2docker fails to download behind corporate proxy
  • Having a custom catalina.sh when using a tomcat image from Docker
  • Docker Alpine image + grpc: Warning: insecure environment read function 'getenv' used
  • Caching docker images locally
  • SkyDNS in Daemon Sets and local DNS resolution
  • One Solution collect form web for “Simulation “docker build -f” with ansible module “docker_image””

    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
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.