RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1278305
Accepted
don Rumata
don Rumata
Asked:2022-05-05 17:35:27 +0000 UTC2022-05-05 17:35:27 +0000 UTC 2022-05-05 17:35:27 +0000 UTC

Ansible 未在 docker 中执行“命令:”

  • 772

主机:ubuntu 18.04

可靠:2.9.20

docker-ce: 5:20.10.6~3-0~ubuntu-bionic

    - name: test container
      when:
        - ansible_system == 'Linux'
        - ansible_architecture == 'x86_64'
      become: yes
      docker_container:
        name: test-01
        hostname: ansible-ubuntu-20-04
        image: diodonfrost/ansible-ubuntu:20.04
        volumes:
          - /tmp/roles:/root/.ansible/roles
        output_logs: yes
        state: started
        command: touch /tmp/1
        interactive: yes
        tty: yes

一个带有ubuntu的虚拟机,它包含一个docker,计划在容器(绝对沙箱)中测试代码。一切都已创建甚至启动,但不知何故我看不到结果。那些。touch /tmp/1挂但不运行:

root@docker-test-01:~# docker container ps
CONTAINER ID   IMAGE                              COMMAND                  CREATED         STATUS         PORTS     NAMES
fc82da6238a4   diodonfrost/ansible-ubuntu:20.04   "/sbin/init touch /tmp/1…"   6 seconds ago   Up 4 seconds             test-01
root@docker-test-01:~# docker container exec test-01 ls /tmp/
hsperfdata_root
root@docker-test-01:~# 

从主机运行 - 一切正常:

root@docker-test-01:~# docker container exec -i -t test-01 touch /tmp/1
root@docker-test-01:~# docker container exec test-01 ls /tmp/
1
hsperfdata_root
root@docker-test-01:~# 

在哪里挖?

升级版。回应评论:

root@docker-test-01:~# docker container ps -a --format "{{ .Command }}"
"/sbin/init w"

不,之后——沉默。

linux
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    don Rumata
    2022-05-08T07:24:19Z2022-05-08T07:24:19Z

    感谢@aleksandr barakin 朝着正确的方向前进。

    因为 如果任务不仅仅是运行一些代码,而是精确地运行它以查看它是否工作,那么如果我们准确返回实际存在的出口会很好。这是一个可以完成它应该做的选项的组合:

    ENTRYPOINT ["/sbin/init"]在这里,我们的团队正在覆盖原始curl文件。在CMDcommand的包装器中,我们将参数传递给并确保不要忘记. 没有它什么都行不通:curldetach: no

    - name: Create test container
      when:
        - ansible_system == 'Linux'
        - ansible_architecture == 'x86_64'
      become: yes
      docker_container:
        name: test-01
        hostname: ansible-ubuntu-20-04
        image: diodonfrost/ansible-ubuntu:20.04
        volumes:
          - /tmp/roles:/root/.ansible/roles
        state: started
        entrypoint: curl
        command: --fail --head "http://example.com/123"
        detach: no
    

    因为 没有文件\目录123-服务器将返回给我们404,--fail说curl'y NOT return exit 0,但是 return exit 22,并且detach: no不会将exit命令中的任何内容转换exit 0为ansible本身。我们得到:

        "msg": "  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\ncurl: (22) The requested URL returned error: 404 Not Found\n", 
        "status": 22
    }
    
    PLAY RECAP *******************************************************************************************************
    docker-test-01.local       : ok=4    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
    

    但是,如果您更改command: --fail --head "http://example.com/123为command: --fail --head "http://example.com/,那么它将index.html在服务器上,他们将在任何地方将其返回给我们,exit 0并且 ansible 排气将是适当的:

                "volumes_from": null, 
                "working_dir": null
            }
        }
    }
    META: ran handlers
    META: ran handlers
    
    PLAY RECAP *******************************************************************************************************
    docker-test-01.local       : ok=5    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
    
    
    • 1

相关问题

  • 如果 fuser -k number/tcp 没有帮助,如何在 Debian 中释放端口?

  • Ubuntu。startx 不起作用。黑屏

  • --syn 在 iptables 中有什么作用?

  • 为什么需要iso格式?

  • C程序中没有密码的sudo

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5