簡體   English   中英

使用卷時無法啟動 nginx 容器(使用 ansible 和 docker-compose)

[英]Failing to start nginx container when volumes is used (using ansible and docker-compose)

我正在嘗試使用 ansible 和 docker-compose 從一台機器啟動一個 nginx 容器到另一台機器。

每當我將 nginx.conf 包含到卷中時,都會出現一個我不明白的錯誤。 容器僅創建但未啟動。

機器1

運行劇本的命令: ansible-playbook -v nginx-playbook.yml -l ubuntu_node_1 -u root

我的劇本:

- name: nginx-docker_compose
  hosts: all
  gather_facts: yes
  become: yes
  tasks:
    - community.general.docker_compose:
        project_name: nginx
        definition:
          version: '2'
          services:
            web:
              image: nginx:latest
              volumes:
                - ./vars/nginx.conf:/etc/nginx/nginx.conf:ro
              ports:
                - "8080:80"

[編輯]

這是錯誤:

Using /etc/ansible/ansible.cfg as config file

PLAY [nginx-docker_compose] ********************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host 172.31.15.176 should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior
Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [172.31.15.176]

TASK [community.general.docker_compose] ********************************************************************************************************************************
fatal: [172.31.15.176]: FAILED! => {"changed": false, "errors": [], "module_stderr": "Recreating nginx_web_1 ... \n\u001b[1A\u001b[2K\nRecreating nginx_web_1 ... \n\u001b[1B", "module_stdout": "", "msg": "Error starting project Encountered errors while bringing up the project."}

PLAY RECAP *************************************************************************************************************************************************************
172.31.15.176              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

[root@ip-172-31-12-130 docker_server]# ansible-playbook -v nginx-playbook.yml -l ubuntu_node_1 -u root
Using /etc/ansible/ansible.cfg as config file

PLAY [nginx-docker_compose] ********************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host 172.31.15.176 should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior
Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [172.31.15.176]

TASK [community.general.docker_compose] ********************************************************************************************************************************
fatal: [172.31.15.176]: FAILED! => {"changed": false, "errors": [], "module_stderr": "Recreating 9b102bbf98c2_nginx_web_1 ... \n\u001b[1A\u001b[2K\nRecreating 9b102bbf98c2_nginx_web_1 ... \n\u001b[1B", "module_stdout": "", "msg": "Error starting project Encountered errors while bringing up the project."}

PLAY RECAP *************************************************************************************************************************************************************
172.31.15.176              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

注意:當我嘗試在 MACHINE-2 上使用具有相同配置的 docker-compose 直接運行 nginx 容器時,它可以工作。 我相信在嘗試從 MACHINE-1 到 MACHINE-2 執行劇本時會發生一些權限問題,但無法弄清楚。

我正在嘗試使用 ansible 和 docker-compose 從一台機器啟動一個 nginx 容器到另一台機器。

每當我將 nginx.conf 包含到卷中時,都會出現一個我不明白的錯誤。 容器僅創建但未啟動。

機器1

運行劇本的命令: ansible-playbook -v nginx-playbook.yml -l ubuntu_node_1 -u root

我的劇本:

- name: nginx-docker_compose
  hosts: all
  gather_facts: yes
  become: yes
  tasks:
    - community.general.docker_compose:
        project_name: nginx
        definition:
          version: '2'
          services:
            web:
              image: nginx:latest
              volumes:
                - ./vars/nginx.conf:/etc/nginx/nginx.conf:ro
              ports:
                - "8080:80"

[編輯]

這是錯誤:

Using /etc/ansible/ansible.cfg as config file

PLAY [nginx-docker_compose] ********************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host 172.31.15.176 should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior
Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [172.31.15.176]

TASK [community.general.docker_compose] ********************************************************************************************************************************
fatal: [172.31.15.176]: FAILED! => {"changed": false, "errors": [], "module_stderr": "Recreating nginx_web_1 ... \n\u001b[1A\u001b[2K\nRecreating nginx_web_1 ... \n\u001b[1B", "module_stdout": "", "msg": "Error starting project Encountered errors while bringing up the project."}

PLAY RECAP *************************************************************************************************************************************************************
172.31.15.176              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

[root@ip-172-31-12-130 docker_server]# ansible-playbook -v nginx-playbook.yml -l ubuntu_node_1 -u root
Using /etc/ansible/ansible.cfg as config file

PLAY [nginx-docker_compose] ********************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host 172.31.15.176 should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior
Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [172.31.15.176]

TASK [community.general.docker_compose] ********************************************************************************************************************************
fatal: [172.31.15.176]: FAILED! => {"changed": false, "errors": [], "module_stderr": "Recreating 9b102bbf98c2_nginx_web_1 ... \n\u001b[1A\u001b[2K\nRecreating 9b102bbf98c2_nginx_web_1 ... \n\u001b[1B", "module_stdout": "", "msg": "Error starting project Encountered errors while bringing up the project."}

PLAY RECAP *************************************************************************************************************************************************************
172.31.15.176              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

注意:當我嘗試在 MACHINE-2 上使用具有相同配置的 docker-compose 直接運行 nginx 容器時,它可以工作。 我相信在嘗試從 MACHINE-1 到 MACHINE-2 執行劇本時會發生一些權限問題,但無法弄清楚。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM