gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:29:18 27 4
gpt4 key购买 nike

我正在尝试在 docker 容器内运行 mvn clean install 命令。但是似乎什么都没有发生,因为我已将容器映射到一个卷并且没有创建目标文件夹。这是剧本。抱歉,如果这是一个愚蠢的问题,但我现在已经被困在这里一段时间了。

---
- 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

我还尝试从 docker-container 模块外部运行命令,但由于容器已经停止,因此会出错。像这样的东西
     - name: copy content in container to some other folder
command: docker exec -i maven_build_direct bash -c 'echo "Hello1"; echo "Hello2"'

上面的错误是

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"]}

最佳答案

正如评论中所指出的,第一个问题是您指定了多个命令属性,这是行不通的。正确的方法是这样设置 workdir 属性:

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

关于maven - 使用 ansible playbook 在 docker 容器内运行 mvn clean install,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52025997/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com