简体   繁体   English

使用 ansible playbook 在 docker 容器内运行 mvn clean install

[英]Running mvn clean install inside docker container using ansible playbook

I am trying to run mvn clean install command inside the docker container.我正在尝试在 docker 容器内运行 mvn clean install 命令。 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.我还尝试从 docker-container 模块外部运行命令,但由于容器已经停止,它给出了错误。 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"]} => {"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": "非零返回码", "rc ": 126, "start": "2018-08-26 17:07:06.782576", "stderr": "", "stderr_lines": [], "stdout": "OCI runtime exec failed: exec failed: cannot exec已停止的容器:未知”,“stdout_lines”:[“OCI 运行时执行失败:执行失败:无法执行已停止的容器:未知”]}

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:执行此操作的正确方法是将 workdir 属性设置为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM