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