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"]}
command
keywords in the samedocker_container
. Why don't you use/proj/mvn clean install
?? – Baptiste Mille-Mathias