2
votes

I am trying to run mvn clean install command inside the docker container. But nothing seems to happen as I have mapped my container to a volume and no target folder is created. This is the playbook. Apologies if this is a silly question but I have been stuck here for some frustating time now.

---
- name: Building project
  hosts: all
  become: true
  become_user: root
  tasks:
     - name: install docker mvn
       docker_container:
          name: maven_build_direct
          image: maven
          volumes:
            - /home/user/Desktop/Training/docker/maven_task/happy/GsaJavaExample/:/proj
          command: cd /proj
          command: mvn clean install

I also tried running commands from outside the docker-container module but since the container already stops it gives error. Something like this

     - name: copy content in container to some other folder
       command: docker exec -i maven_build_direct bash -c 'echo "Hello1"; echo "Hello2"'

The error for the above is

fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["docker", "exec", "-i", "maven_build_direct", "bash", "-c", "echo \"Hello1\"; echo \"Hello2\""], "delta": "0:00:00.212534", "end": "2018-08-26 17:07:06.995110", "msg": "non-zero return code", "rc": 126, "start": "2018-08-26 17:07:06.782576", "stderr": "", "stderr_lines": [], "stdout": "OCI runtime exec failed: exec failed: cannot exec a container that has stopped: unknown", "stdout_lines": ["OCI runtime exec failed: exec failed: cannot exec a container that has stopped: unknown"]}

1
@baptistemm yes ... thats when i run from outside the module. I tried using run .. gives no error but no target createdShaurya
you can't have 2 command keywords in the same docker_container. Why don't you use /proj/mvn clean install ??Baptiste Mille-Mathias
so how can i go to the directory where pom.xml is and run mvn install. Tried cd /project && mvn clean install. No changes. Oh ok saw laterShaurya
@baptistemm Tried it but no target folder created and also no error.Shaurya

1 Answers

1
votes

As pointed out in the comments, the first problem is that you are specifying multiple command properties, which won't work. The proper way to do this, is to set the workdir property as such:

      ...
      volumes:
        - /home/user/Desktop/Training/docker/maven_task/happy/GsaJavaExample/:/proj
      working_dir: /proj
      command: mvn clean install
      ...